2014-10-29 62 views
1

我在WSO2 ESB中使用XSLT中介將我的傳統服務響應轉換爲CDM服務響應。但它不工作,我已經嘗試了它在一個獨立的在線編輯器http://xslt.online-toolz.com/tools/xslt-transformation.php它工作正常。但是在WSO2中,我的XSLT不起作用。XSLT在聯機編輯器中工作正常但不在WSO2 ESB中

遺留響應:

<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>[email protected]</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> 

XSLT:

<xsl:stylesheet version="1.0" 
xmlns="http://com.example.com/xsd/Person_01_RequestResponse_001" 
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="GetPersonResponse"> 
<xsl:apply-templates select="//m0:Religion"/> 
</xsl:template>      
<xsl:template match="//m0:Religion"> 
<xsl:value-of select="//m0:DateOfBirth"/> 

</xsl:template> 


</xsl:stylesheet> 

XSLT中保:

<xslt key="gov:/repository/components/TestXSLT.xslt"> 

     <resource location="TestXSLT.xslt" key="gov:/repository/components/TestXSLT.xslt"></resource> 
    </xslt> 

錯誤WSO2測試環境:

<getBusRootResponse> 
    <error> 
     <errorCode>101508</errorCode> 
     <errorMsgTitle>Connection Time Out</errorMsgTitle> 
     <errorMsg>We are unable to get Connection to BusRoot Services</errorMsg> 
    </error> 
</getBusRootResponse> 

錯誤WSO2系統日誌:

ERROR_EXCEPTION : org.apache.synapse.SynapseException: Unable to perform XSLT transformation using : Value {name ='null', keyValue ='gov:/repository/components/TestXSLT.xslt'} against source XPath : s11:Body/child::*[position()=1] | s12:Body/child::*[position()=1] reason : Unable to create an OMElement using XSLT result 

回答

1

您的XSLT工作不細,在http://xslt.online-toolz.com/tools/xslt-transformation.php再次測試:結果不是XML,但平文本和ESB無法處理這樣的結果

此示例替換宗教節點值與值爲FatherName節點:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns6="http://com.example.com/xsd/Person_01" version="2.0" exclude-result-prefixes="xsl fo xs fn"> 
    <xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="no"/> 
    <xsl:template match="ns6:Religion"> 
     <ns6:Religion><xsl:value-of select="../ns6:FatherName"/></ns6:Religion> 
    </xsl:template> 
    <xsl:template match="@*|*|comment()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|*|text()|comment()|processing-instruction()"/> 
     </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 
+0

能否請你指出的錯誤在我的XSLT .. – 2014-10-30 03:54:19

+0

我已經更新了我的答案與樣本 – 2014-10-30 08:30:13

相關問題