从命名空间获取节点名称
get node name from namespace
这是我的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() 很多其他方法,但是没有运气,我不能只检索节点名称,任何帮助都可以,谢谢!
您可以尝试使用 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 I used for testing, there was error when root element is absent. Usually, setting <xsl:output>
is enough to be able to output a non-XML result : XSLT: Transforming into non-xml content?
这是我的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() 很多其他方法,但是没有运气,我不能只检索节点名称,任何帮助都可以,谢谢!
您可以尝试使用 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 I used for testing, there was error when root element is absent. Usually, setting <xsl:output>
is enough to be able to output a non-XML result : XSLT: Transforming into non-xml content?