开发者

Remove empty attributes in XSLT

开发者 https://www.devze.com 2023-03-26 09:57 出处:网络
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

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&开发者_开发问答gt;


<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


Well the only place where you process attribute nodes is <xsl:apply-templates select="@*"> so changing that to <xsl:apply-templates select="@*[normalize-space()]"> might suffice.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号