命名空间元素的XSLT

时间:2017-08-06 13:38:54

标签: xml xslt

以下列格式输入XML:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header/>
  <s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ResponseData xmlns="http://testify.com/maxi">
      <VALID>true</VALID>
      <ERROR_DESC xsi:nil="true"> something gone wrong </ERROR_DESC>
    </ResponseData>
  </s:Body>
</s:Envelope>

由于命名空间的复杂性,很难将其转换为以下格式。

<STATUS>
  <VALID> TRUE </VALID>
  <ERROR_DESC> something gone wrong  </ERROR_DESC>
</STATUS>

我尝试了几个选项却没有成功。下面没有数据。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:output method="xml" encoding="utf-8" indent="no"/>
<xsl:template match="/">
  <xsl:value-of select="s:Envelope//s:Body/s:ResponseData"/>
</xsl:template>


  <xsl:template match="s:ResponseData">
    <xsl:element name="width">
      <xsl:value-of select="s:VALID"/>
    </xsl:element>
  </xsl:template>


</xsl:stylesheet>

1 个答案:

答案 0 :(得分:3)

要获得问题中指定的结果,您需要:

(a)在寻址utilities.Driver.Initialize(Driver.java:34)元素及其子元素时使用正确的命名空间;和
 (b)通过向他们应用模板来实际处理ResponseData的孩子。

XSLT 1.0

ResponseData

请注意,没有复制任何内容以便不复制命名空间。

相关问题