lajarre
lajarre

Reputation: 5162

XSLT - remove all attributes

Pretty straightforward question. Didn't find an answer to exactly this one.

Would like to see XSLT 1.0 without attribute axis, and others too if possible (I am using python's lxml lib which is not really catching up on that stuff).

Upvotes: 2

Views: 5413

Answers (2)

JLRishe
JLRishe

Reputation: 101662

Your solution should work without issue, but there's an even easier way - just use an identity template that doesn't include attributes:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="node()">
    <xsl:copy>
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

Upvotes: 8

lajarre
lajarre

Reputation: 5162

I figured it out by myself while writing the question. Still posting it since it's nowhere I found:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="node()|@*" name="identity">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="@*"/>

</xsl:stylesheet>

Waiting for other answers / comments in case it's not perfect like that.

Upvotes: 0

Related Questions