简体   繁体   English

将Map消息转换为Soap消息在Mule中使用xslt

[英]Transform Soap message to soap message use xslt in Mule

I want transform soap message to soap message use xslt in mule 我想将肥皂消息转换为肥皂消息在m子中使用xslt

I not get element to soap message 1 to soap message 2 我没有获得肥皂消息1到肥皂消息2的元素

1. I have soap 1.我有肥皂

<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 这是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. 另一个是Students元素及其后代位于一个名称空间中,并且需要使用绑定到同一名称空间的前缀才能选择它们。

Here's your stylesheet with some modifications: 这是您的样式表,进行了一些修改:

XSLT 1.0 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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