简体   繁体   中英

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).

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM