使用XSLT解析肥皂响应

时间:2019-02-22 12:19:04

标签: xml xslt

我正在尝试使用XSLT解析SOAP响应,但出现错误。我是XSLT的初学者。

Unable to generate the XML document using the provided XML/XSL input. Errors were reported during stylesheet compilation

XML响应

<?xml version="1.0" encoding="UTF-8"/>
  <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
       <ns0:response xmlns:ns0="http://ws.ejb.interfaces70.abc.aspace.com/">
         <return>
            <check>
              <code>code_value</code>
             </check>
          </return>
        </ns0:primaryAuthenticateUPResponse>
      </S:Body>
    </S:Envelope>

XSLT

  <?xml version="1.0" ?>
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://ws.ejb.interfaces70.abc.aspace.com/">
    <xsl:template match="/">
      <b><xsl:value-of select="S:Envelope/S:Body/ns0:response/return/check/code/" /></b>
    </xsl:template>
  </xsl:stylesheet>

2 个答案:

答案 0 :(得分:0)

尝试删除以下位置的最后一个/

<xsl:value-of select="S:Envelope/S:Body/ns0:response/return/check/code/" />

使其变为:

<xsl:value-of select="S:Envelope/S:Body/ns0:response/return/check/code" />

未经测试,因为您的XML无法使用。

答案 1 :(得分:0)

假设您的XML经过更正:

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
   <ns0:response xmlns:ns0="http://ws.ejb.interfaces70.abc.aspace.com/">
     <return>
        <check>
          <code>code_value</code>
         </check>
      </return>
    </ns0:response>
  </S:Body>
</S:Envelope>

并更正了xslt:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" 
  xmlns:ns0="http://ws.ejb.interfaces70.abc.aspace.com/">

  <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:template match="/">
      <b><xsl:value-of select="S:Envelope/S:Body/ns0:response/return/check/code" /></b>
    </xsl:template>
  </xsl:stylesheet>