如何使用xslt从xml删除所有空标签

时间:2019-01-31 08:16:34

标签: xml xslt

我的xml是:

    <content type="text/html" title="flow-active-timeout">
<body>    
    <dl>
    </dl>
    <p>&#160;</p>

    <div mt-section-origin="Product_Documentation/Command_Reference/Configuration_Commands/flow-active-timeout" class="mt-section" id="section_1"><span id="vManage_Feature_Template"></span><h2 class="editable">vManage Feature Template</h2>

    <p>For vSmart controllers:</p>

    <p>Configuration &#9658; Policies&#160;&#9658; Centralized Policy</p>

    </div>
</body>

我的xslt代码是:

<xsl:template match="*[not(normalize-space(translate(., '&#160;', ' ')))]"/>

但它只会删除空的<p>标签而不是<dl>标签

使用上面的xslt输出:

<body>
<dl/>
<div mt-section-origin="Product_Documentation/Command_Reference/Configuration_Commands/flow-active-timeout" class="mt-section" id="section_1"><span id="vManage_Feature_Template"></span><h2 class="editable">vManage Feature Template</h2>

    <p>For vSmart controllers:</p>

    <p>Configuration &#9658; Policies&#160;&#9658; Centralized Policy</p>

    </div>
</body>

预期输出为:

    <body>
<div mt-section-origin="Product_Documentation/Command_Reference/Configuration_Commands/flow-active-timeout" class="mt-section" id="section_1"><span id="vManage_Feature_Template"></span><h2 class="editable">vManage Feature Template</h2>

    <p>For vSmart controllers:</p>

    <p>Configuration &#9658; Policies&#160;&#9658; Centralized Policy</p>

    </div>
</body>

请提供一些说明以实现预期的输出

1 个答案:

答案 0 :(得分:0)

<xsl:template match="*[text()='&#160;' or  normalize-space(.)='']"/>
You may also use like this
相关问题