繁体   English   中英

删除XSLT中的空属性

[英]Remove empty attributes in XSLT

我正在尝试对所有元素进行排序,然后对属性进行排序,该IVE就起作用了,但是我一生都不知道如何删除空的属性

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

谢谢你的帮助

好吧,处理属性节点的唯一地方是<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM