Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 当标记没有值但属性存在时,需要XSLT删除标记_Xml_Xslt_Xml Parsing_Remove - Fatal编程技术网

Xml 当标记没有值但属性存在时,需要XSLT删除标记

Xml 当标记没有值但属性存在时,需要XSLT删除标记,xml,xslt,xml-parsing,remove,Xml,Xslt,Xml Parsing,Remove,我有XSLT,如果标签的值为空/null,它可以很好地删除标签。但我无法删除具有以下结构的标签: <cbc:LineExtensionAmount currencyID="EUR"/> inputXML: <cbc:LineTotal currencyID="EUR">1989.65</cbc:LineTotal> <cbc:LineAmount currencyID="EUR"/>

我有XSLT,如果标签的值为空/null,它可以很好地删除标签。但我无法删除具有以下结构的标签:

<cbc:LineExtensionAmount currencyID="EUR"/>

inputXML:

<cbc:LineTotal currencyID="EUR">1989.65</cbc:LineTotal>
<cbc:LineAmount currencyID="EUR"/>
<cbc:dummy/>
1989.65
预期产出:

<cbc:LineTotal currencyID="EUR">1989.65</cbc:LineTotal>
1989.65
我当前的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>


任何建议/建议都将非常有用。

这对您有用吗:

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

很好。如果你的问题得到了回答,请通过接受答案来结束它。