2013-04-03 121 views
2

非常简单的问题。没有找到正确的答案。XSLT - 删除所有属性

希望看到XSLT 1.0没有属性轴,如果可能的话还有其他的(我正在使用python的lxml库,它并没有真正追上那些东西)。

回答

8

您的解决方案应该没有问题,但有一个更简单的方法 - 只需使用一个身份模板不包含属性:

<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> 
+0

酷!看起来很明显,当你看到它 – lajarre 2013-04-04 09:49:32

0

我在写这个问题时自己想出了它。仍然发布它,因为它是无处我发现:

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

等待其他答案/评论,如果它不是那么完美。

+0

虽然这肯定的作品,@ JLRishe的回答是更容易。 – ABach 2013-04-03 19:58:15