0

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?

Alp
  • 29,274
  • 27
  • 120
  • 198

1 Answers1

1

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.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110