【问题标题】:XSLT File Not working in WSO2 ESBXSLT 文件在 WSO2 ESB 中不起作用
【发布时间】:2014-10-29 07:26:21
【问题描述】:

我想将我的旧服务响应转换为 CDM 服务响应。为此,我在 WSO2 ESB 中使用 XSLT Mediator。我对我的 XSLT 的语法感到困惑。我这样做是否正确? XSLT 中介工作正常。我已经确认了。 我首先在在线工具上尝试http://xslt.online-toolz.com/tools/xslt-transformation.php

旧版响应(输入):

<GetPersonResponse xmlns="http://com.example.com/xsd/Person_01_RequestResponse_001">
   <Person xsi:type="ns1:Person" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <ns2:PersonId xmlns:ns2="http://com.example.com/xsd/Person_01">4224</ns2:PersonId>
      <ns3:FirstName xmlns:ns3="http://com.example.com/xsd/Person_01">John</ns3:FirstName>
      <ns4:LastName xmlns:ns4="http://com.example.com/xsd/Person_01">Doe</ns4:LastName>
      <ns5:FatherName xmlns:ns5="http://com.example.com/xsd/Person_01">Khalid</ns5:FatherName>
      <ns6:Religion xmlns:ns6="http://com.example.com/xsd/Person_01">Islam</ns6:Religion>
      <ns7:MotherTongue xmlns:ns7="http://com.example.com/xsd/Person_01">Urrdu</ns7:MotherTongue>
      <ns8:DateOfBirth xmlns:ns8="http://com.example.com/xsd/Person_01">1893-02-02</ns8:DateOfBirth>
      <ns9:Gender xmlns:ns9="http://com.example.com/xsd/Person_01" xsi:type="ns1:GenderType">Male</ns9:Gender>
      <ns10:CurrentAddress xmlns:ns10="http://com.example.com/xsd/Person_01" xsi:type="ns1:AddressDetail">
         <ns10:AddressDetailId>194</ns10:AddressDetailId>
         <ns10:StreetNo>5</ns10:StreetNo>
         <ns10:HouseNo>123</ns10:HouseNo>
         <ns10:Town>Johar</ns10:Town>
         <ns10:District>Lahore</ns10:District>
         <ns10:City>Lahore</ns10:City>
         <ns10:State>Punjab</ns10:State>
         <ns10:Country>Pakistan</ns10:Country>
         <ns10:Postal>54000</ns10:Postal>
      </ns10:CurrentAddress>
      <ns11:HomeAddress xmlns:ns11="http://com.example.com/xsd/Person_01" xsi:type="ns1:AddressDetail">
         <ns11:AddressDetailId>195</ns11:AddressDetailId>
         <ns11:StreetNo>5</ns11:StreetNo>
         <ns11:HouseNo>123</ns11:HouseNo>
         <ns11:Town>Johar</ns11:Town>
         <ns11:District>Lahore</ns11:District>
         <ns11:City>Lahore</ns11:City>
         <ns11:State>Punjab</ns11:State>
         <ns11:Country>Pakistan</ns11:Country>
         <ns11:Postal>54000</ns11:Postal>
      </ns11:HomeAddress>
      <ns12:Height xmlns:ns12="http://com.example.com/xsd/Person_01">6</ns12:Height>
      <ns13:Weight xmlns:ns13="http://com.example.com/xsd/Person_01">100</ns13:Weight>
      <ns14:CNIC xmlns:ns14="http://com.example.com/xsd/Person_01">35302</ns14:CNIC>
      <ns15:ContactInfo xmlns:ns15="http://com.example.com/xsd/Person_01" xsi:type="ns1:ContactDetail">
         <ns15:HomePhone>454545</ns15:HomePhone>
         <ns15:CellPhone>3343434</ns15:CellPhone>
         <ns15:WorkPlacePhone>34343434</ns15:WorkPlacePhone>
         <ns15:Email>omer@gmail.com</ns15:Email>
      </ns15:ContactInfo>
      <ns16:MaritalStatus xmlns:ns16="http://com.example.com/xsd/Person_01">Single</ns16:MaritalStatus>
      <ns17:Nationality xmlns:ns17="http://com.example.com/xsd/Person_01">Pakistani</ns17:Nationality>
   </Person>
   <ResponseCode>PERSON MODULE SUCCESS - 00</ResponseCode>
   <ResponseMessage>Data Fetched Successfully</ResponseMessage>
</GetPersonResponse> 

应该是什么输出:

我只想更改“Religon”元素的值并将其值替换为“FatherName”元素值。其余响应应保持不变。

我的 XSLT:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:m0="http://com.example.com/xsd/Person_01">
    <xsl:output method="xml" encoding="utf-8" indent="yes"/>

    <xsl:template match="//m0:GetPersonResponse">
    <xsl:apply-templates select="//m0:Religion"/>
    </xsl:template>                     

    <xsl:template match="//m0:Religion">
    <xsl:value-of select="//m0:FatherName"/>
    </xsl:template>


</xsl:stylesheet>

我已经通过删除命名空间进行了尝试,但它也不起作用。

【问题讨论】:

    标签: xml xslt xml-parsing wso2 wso2esb


    【解决方案1】:

    GetPersonResponse 的命名空间是http://com.example.com/xsd/Person_01_RequestResponse_001 必须指定 THIS 命名空间,不能删除它或使用 m0 引用“http://com.example.com/xsd/Person_01

    然而,m0 是 Religion 节点的正确命名空间

    【讨论】:

      猜你喜欢
      • 2015-05-05
      • 2013-09-10
      • 2017-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多