从命名空间中获取节点名称

时间:2015-06-10 04:02:29

标签: xslt xslt-1.0

这是我的xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:end="http://endpoint.ggg.com/">

   <soapenv:Header/>
   <soapenv:Body>
      <end:onlineExpressRemit>
      <channelCode>NBPS</channelCode>
      </end:onlineExpressRemit>
   </soapenv:Body>
    </soapenv:Envelope>

这是我的xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:end="http://endpoint.ggg.com/" >

    <xsl:template match="/">
<xsl:value-of name="ggg2" select="/soapenv:Envelope/soapenv:Body/*[namespace-uri()]"/>
    </xsl:template>
</xsl:stylesheet>

我的预期输出仅显示

onlineExpressRemit

我是xslt的新手,我尝试使用name(),local-name()以及其他方法,但是没有运气,我只能检索节点名,任何帮助都会做,谢谢!

1 个答案:

答案 0 :(得分:0)

您可以尝试使用local-name(soapenv:Envelope/soapenv:Body/*),例如,以下XSL转换:

<xsl:stylesheet version="1.0" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:end="http://endpoint.ggg.com/" >

    <xsl:output method="text" omit-xml-declaration="yes"/>

    <xsl:template match="/">
        <xsl:element name="root">
            <xsl:value-of select="local-name(soapenv:Envelope/soapenv:Body/*)"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

应用于XML示例时,产生以下输出:

<root>onlineExpressRemit</root>

注意:我添加<root>元素只是因为在我用于测试的online XSLT processor中,当根元素不存在时出错。通常,设置<xsl:output>足以输出非XML结果:XSLT: Transforming into non-xml content?

相关问题