我有XSLT,如果标记的值为空/null,它可以很好地删除标记。
但是我不能删除具有以下结构的标签:
<cbc:LineExtensionAmount currencyID="EUR"/>inputXML:
<cbc:LineTotal currencyID="EUR">1989.65</cbc:LineTotal>
<cbc:LineAmount currencyID="EUR"/>
<cbc:dummy/>预期输出:
<cbc:LineTotal currencyID="EUR">1989.65</cbc:LineTotal>我目前的XSLT如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="node()">
<xsl:if test="normalize-space(string(.)) != ''
or count(@*[normalize-space(string(.)) != '']) > 0
or count(descendant::*[normalize-space(string(.)) != '']) > 0
or count(descendant::*/@*[normalize-space(string(.)) != '']) > 0">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="@*">
<xsl:if test="normalize-space(string(.)) != ''">
<xsl:copy>
<xsl:apply-templates select="@*" />
</xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>发布于 2020-09-05 04:21:43
这对你有用吗:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- remove elements with no content other than attributes -->
<xsl:template match="*[not(node())]"/>
</xsl:stylesheet>https://stackoverflow.com/questions/63747497
复制相似问题