简体   繁体   中英

Remove empty attributes in XSLT

Im trying to sort all elements, then attributes, which ive got working, however i cant figure out for the life of me how to remove attributes that are empty

Here is the sort XSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="@* | node()">
    <xsl:copy>

        <xsl:apply-templates >
            <xsl:sort select="local-name()"/>
        </xsl:apply-templates>

    </xsl:copy>
</xsl:template>


<xsl:template match="*[*]">

    <xsl:copy>
        <xsl:apply-templates select="@*" >
            <xsl:sort select="local-name()" />
        </xsl:apply-templates>

        <xsl:apply-templates select="*" >
            <xsl:sort select="local-name()"/>
        </xsl:apply-templates>

    </xsl:copy>
</xsl:template>

Thanks for any help

好吧,处理属性节点的唯一地方是<xsl:apply-templates select="@*">因此将其更改为<xsl:apply-templates select="@*[normalize-space()]">可能就足够了。

<xsl:template match="@*">
    <xsl:if test="string-length(.)!=0">
        <xsl:copy />
    </xsl:if>
</xsl:template>

<xsl:template match="node()"> <!-- replaces the "match='@* | node()'" template -->
    <xsl:copy>
        <xsl:apply-templates >
            <xsl:sort select="local-name()"/>
        </xsl:apply-templates>
    </xsl:copy>
</xsl:template>

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