2014-11-25 54 views
1

的XSL轉換這是我的響應消息:沒有一個馬克西莫響應

<?xml version="1.0" encoding="UTF-16"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
<soapenv:Body> 
    <QueryMXCPISResponse baseLanguage="EN" 
     creationDateTime="2014-11-25T11:56:09+01:00" 
     maximoVersion="7 5 20130829-1209 V7510--1" 
     messageID="1416912970550686680" rsCount="3" rsStart="0" 
     rsTotal="3" transLanguage="EN" 
     xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
     <MXCPISSet> 
      <CPIS> 
       <AK>D</AK> 
       <CPISID>630124</CPISID> 
       <ORGID>01</ORGID> 
       <S1>0</S1> 
       <S2>0</S2> 
       <S3>0</S3> 
       <S4>0</S4> 
       <S5>0</S5> 
       <S6>1</S6> 
       <SHIFT>3</SHIFT> 
       <SHIFTDATE>2014-09-30T00:00:00+02:00</SHIFTDATE> 
       <SITEID>0030</SITEID> 
       <STATUS>NEW</STATUS> 
       <TEAM>C</TEAM> 
       <WP>LC11</WP> 
       <ASSET> 
        <ASSETNUM>LC11</ASSETNUM> 
        <LOCATION>FACILITY-1</LOCATION> 
        <SITEID>0030</SITEID> 
       </ASSET> 
      </CPIS> 
      <CPIS> 
       <AK>D</AK> 
       <CPISID>630121</CPISID> 
       <ORGID>01</ORGID> 
       <S1>0</S1> 
       <S2>0</S2> 
       <S3>1</S3> 
       <S4>0</S4> 
       <S5>0</S5> 
       <S6>1</S6> 
       <SHIFT>1</SHIFT> 
       <SHIFTDATE>2014-09-30T00:00:00+02:00</SHIFTDATE> 
       <SITEID>0030</SITEID> 
       <STATUS>CHECKED</STATUS> 
       <TEAM>B</TEAM> 
       <WP>LC11</WP> 
       <ASSET> 
        <ASSETNUM>LC11</ASSETNUM> 
        <LOCATION>FACILITY-1</LOCATION> 
        <SITEID>0030</SITEID> 
       </ASSET> 
      </CPIS> 
      <CPIS> 
       <AK>D</AK> 
       <CPISID>630122</CPISID> 
       <ORGID>01</ORGID> 
       <S1>1</S1> 
       <S2>1</S2> 
       <S3>0</S3> 
       <S4>0</S4> 
       <S5>0</S5> 
       <S6>1</S6> 
       <SHIFT>2</SHIFT> 
       <SHIFTDATE>2014-09-30T00:00:00+02:00</SHIFTDATE> 
       <SITEID>0030</SITEID> 
       <STATUS>APPLIED</STATUS> 
       <TEAM>B</TEAM> 
       <WP>LC11</WP> 
       <ASSET> 
        <ASSETNUM>LC11</ASSETNUM> 
        <LOCATION>FACILITY-1</LOCATION> 
        <SITEID>0030</SITEID> 
       </ASSET> 
      </CPIS> 
     </MXCPISSet> 
    </QueryMXCPISResponse> 
</soapenv:Body> 

而且這是我的xsl:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<!-- Edited by XMLSpy® --> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 

<xsl:template match="MXCPISSet"> 
<html> 
    <body> 

    <table> 
    <tbody> 
    <tr> 
     <th>WP</th> 
     <th>Site</th> 
     <th>Shift</th> 
    </tr> 

    <xsl:for-each select="CPIS"> 
    <tr> 
     <td><xsl:value-of select="WP"/></td> 
     <td><xsl:value-of select="ASSET/SITEID"/></td> 
     <td><xsl:value-of select="SHIFT"/></td> 
    </tr> 
    </xsl:for-each> 

    </tbody> 
    </table> 


    </body> 
</html> 
</xsl:template> 

</xsl:stylesheet> 

這是結果:

D 630124 01 0 0 0 0 0 1 3 2014-09-30T00:00:00+02:00 0030 NEW C LC11 LC11 FACILITY-1 0030 D 630121 01 0 0 1 0 0 1 1 2014-09-30T00:00:00+02:00 0030 CHECKED B LC11 LC11 FACILITY-1 0030 D 630122 01 1 1 0 0 0 1 2 2014-09-30T00:00:00+02:00 0030 APPLIED B LC11 LC11 FACILITY-1 0030 

如果我刪除xmlns =「http://www.i bm.com/maximo」從響應消息我得到正確的輸出

WP  Site Shift 
LC11 0030 3 
LC11 0030 1 
LC11 0030 2 

什麼是錯誤的,我的XSL文件,我沒有得到HTML輸出?

回答

2

元素QueryMXCPISResponse,MXCPISSet等位於命名空間xmlns="http://www.ibm.com/maximo"中。沒有名稱空間,處理器不匹配任何元素,而是應用您的樣式表,而不是應用default processing rules。你需要適應這個命名空間在你的模板,如下所示(請注意xmlns和別名,m爲馬克西莫):

<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       version="1.0" 
       xmlns:m="http://www.ibm.com/maximo" 
       xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
       exclude-result-prefixes="soapenv m"> 

    <xsl:output method="html"/> 

    <xsl:template match="/" > 
    <xsl:apply-templates select="m:QueryMXCPISResponse/m:MXCPISSet" /> 
    </xsl:template> 

    <xsl:template match="m:MXCPISSet"> 
    <html> 
     <body> 
     <table> 
      <tbody> 
      <tr> 
       <th>WP</th> 
       <th>Site</th> 
       <th>Shift</th> 
      </tr> 
      <xsl:for-each select="m:CPIS"> 
      ... etc. 

其他信息:

  • 除非你只是轉化的有效載荷在SOAP主體中,您可能需要對SOAP標頭執行相同的操作。xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  • 如果目標是Html,則還應該在樣式表中設置<xsl:output method="html"/>
  • 可以潛在地幹起來你的模板進一步apply-templates,優先於xsl:for-each
+0

謝謝。現在它工作得很好。 – Thomas 2014-11-27 11:24:53

相關問題