XSLT - remove all attributes

佐手、 提交于 2019-12-22 15:23:14

问题


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


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/15795152/xslt-remove-all-attributes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!