如何获取样式表中定义的命名空间前缀,而不是从输入 XML 中获取 [英] How to get namespace prefix as defined in stylesheet and not from input XML
本文介绍了如何获取样式表中定义的命名空间前缀,而不是从输入 XML 中获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个输入 XML:
I have this input XML:
<x:html xmlns:x="http://www.w3.org/1999/xhtml"/>
我正在使用以下 XSLT:
and I am using the following XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:y="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="text" indent="yes"/>
<xsl:template match="*">
<xsl:value-of select="name()"/>
</xsl:template>
</xsl:stylesheet>
我得到的输出是(带有前缀 x
的根元素,如输入 XML 中所定义)
The output I am getting is (root element with prefix x
, as defined in input XML)
x:html
我期望的输出是(在 XSLT 中定义的带有前缀 y
的根元素):
The output I expect is (root element with prefix y
, as defined in the XSLT):
y:html
推荐答案
你可以查看 namepace 轴 例如
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:y="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="text" indent="yes"/>
<xsl:variable name="xslt-root" select="document('')/*"/>
<xsl:template match="*">
<xsl:value-of select="concat(local-name($xslt-root/namespace::*[. = namespace-uri(current())]), ':', local-name())"/>
</xsl:template>
</xsl:stylesheet>
这篇关于如何获取样式表中定义的命名空间前缀,而不是从输入 XML 中获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文