简体   繁体   中英

Transform Soap message to soap message use xslt in Mule

I want transform soap message to soap message use xslt in mule

I not get element to soap message 1 to soap message 2

1. I have soap

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<ns:topic xmlns:ns="http://wso2.org/ns/2009/09/eventing/notify">polling_Topic</ns:topic>
</soapenv:Header>
<soapenv:Body>

<data-services-event>

<service-name>pollingService</service-name>
<query-id>pollingQuery</query-id>
<time>Wed May 24 10:01:18 ICT 2017</time>

<content>
<Students xmlns="http://ws.wso2.org/dataservice/samples/eventing_sample">
<student>

<count>25</count>
<id>25</id>
<Name>Tran Anh</Name>
<Contact>Dong Thap</Contact>
<regdatetime>2017-05-23T14:41:35.000+07:00</regdatetime>

</student>
</Students>
</content>

</data-services-event>

</soapenv:Body>
</soapenv:Envelope>
</soap:Body>
</soap:Envelope>

this is transform.xsl

<?xml version="1.0" encoding="UTF-8"?>         
    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>          
        <xsl:template match="/">
            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"                                         xmlns:dat="http://dataservice.ws.wso2.org">
                      <soapenv:Header/>
                      <soapenv:Body>
                         <dat:insertPerson>
                            <!--Optional:--><dat:name><xsl:value-of select="soapenv:Envelope/soapenv:Body/data-services-event/content/Students/student/Name" /></dat:name>
                            <!--Optional:--><dat:contact><xsl:value-of select="data-services-event/content/Students/student/Contact/text()" /></dat:contact>

                         </dat:insertPerson>
                      </soapenv:Body>
             </soapenv:Envelope>    
        </xsl:template>
    </xsl:stylesheet>

I get result:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:dat="http://dataservice.ws.wso2.org"
                  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <dat:insertPerson>
         <dat:name/>
         <dat:contact/>         
      </dat:insertPerson>
   </soapenv:Body>
</soapenv:Envelope>

I not get element: Name and Contact

How to do it

There are two reasons why you don't get the expected values. One is that your paths are missing some location steps. The other is that the Students element and its descendants are in a namespace, and you need to use a prefix bound to the same namespace in order to select them.

Here's your stylesheet with some modifications:

XSLT 1.0

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dat="http://dataservice.ws.wso2.org"
xmlns:stu="http://ws.wso2.org/dataservice/samples/eventing_sample"
exclude-result-prefixes="stu">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>          

<xsl:template match="/">
    <soapenv:Envelope >
        <soapenv:Header/>
        <soapenv:Body>
            <dat:insertPerson>
                <dat:name>
                    <xsl:value-of select="soapenv:Envelope/soapenv:Body/soapenv:Envelope/soapenv:Body/data-services-event/content/stu:Students/stu:student/stu:Name" />
                </dat:name>
                <dat:contact>
                    <xsl:value-of select="soapenv:Envelope/soapenv:Body/soapenv:Envelope/soapenv:Body/data-services-event/content/stu:Students/stu:student/stu:Contact" />
                </dat:contact>
            </dat:insertPerson>
        </soapenv:Body>
    </soapenv:Envelope>    
</xsl:template>

</xsl:stylesheet>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM