相关疑难解决方法(0)

使用XSLT递归删除空的xml元素

我试图以递归方式从xml中删除"空"元素(没有子元素,没有属性或空属性).这是我的XSLT

<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="*[not(*) and
                       string-length(.)=0 and
                       (not(@*) or @*[string-length(.)=0])]">
    <xsl:apply-templates/>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

这是输入XML.我希望这个XML转换为空字符串

<world>
    <country>
        <state>
            <city>
                <suburb1></suburb1>
                <suburb2></suburb2>
            </city>
        </state>
    </country>
</world>
Run Code Online (Sandbox Code Playgroud)

但相反,我得到了

<world>
    <country>
        <state/>
    </country>
</world>
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?我在论坛上研究了很多线程,但仍然没有运气.

xml xslt recursion

2
推荐指数
1
解决办法
1833
查看次数

标签 统计

recursion ×1

xml ×1

xslt ×1