How to eliminate all and all attribute=“” by XSLT?

后端 未结 1 1033
不知归路
不知归路 2021-01-24 01:39

In a xsl:stylesheet I have this \"identity like\" transform, to eliminate comments, empty (terminal) tags and empty attributes... But the second xsl:

相关标签:
1条回答
  • 2021-01-24 02:14

    An empty element is an element with no child nodes.

    Template match priority is your friend ... the following should be the kind of identity stylesheet that meets your description plus what I think you are doing with image and break elements.

    <?xml version="1.0" encoding="US-ASCII"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    version="1.0">
    
    <!--toss these-->
    <xsl:template match="comment() | 
                        *[not(node())] |
                        @*[not(normalize-space())]"/>
    
    <!--preserve these-->
    <xsl:template match="img|br" priority="1">
      <xsl:call-template name="identity"/>
    </xsl:template>
    
    <!--preserve everything else-->
    <xsl:template match="@*|node()" name="identity">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:template>
    
    </xsl:stylesheet>
    
    0 讨论(0)
提交回复
热议问题