当前位置: 动力学知识库 > 问答 > 编程问答 >

xml - XSLT 2.0 template matching - strip all attributes which are not in the desired namespace

问题描述:

I have an XML with differently namespaced attributes - it's basicly a kind of extended XHTML. I want to dump all the non-xhtml namespaced attributes.

Examplary source XML:

<html>

<body>

<p class="test" xy:foo="true">blah</p>

</body>

</html>

At the moment, i have the following XSLT template:

<xsl:template match="@*">

<xsl:choose>

<xsl:when test='namespace-uri()="http://www.w3.org/1999/xhtml"'><xsl:copy-of select="."/></xsl:when>

<xsl:otherwise></xsl:otherwise>

</xsl:choose>

</xsl:template>

Desired output XML:

<html>

<body>

<p class="test">blah</p>

</body>

</html>

But it doesn't seem to match, because i get an output XML completely without attributes. I have the feeling that namespace-uri() does not work as expected. Any ideas?

网友答案:

The attributes on XHTML elements (like your class one) are attributes in no namespace, not in the XHTML namespace. So use

<xsl:template match="@*[namespace-uri() != '']"/>

plus the identity transformation template.

分享给朋友:
您可能感兴趣的文章:
随机阅读: