xml – XSLT复制除1个元素之外的所有节点

前端之家收集整理的这篇文章主要介绍了xml – XSLT复制除1个元素之外的所有节点前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<events>
    <main>
        <action>modification</action>
        <subAction>weights</subAction>
    </main>
</events>
<SeriesSet>
    <Series id="Price_0">
        <seriesBodies>
            <SeriesBody>
                <DataSeriesBodyType>Do Not Copy</DataSeriesBodyType>
            </SeriesBody>
        </SeriesBodies>
    </Series>
</SeriesSet>

如何复制所有xml并排除DataSeriesBodyType元素

您只需使用身份模板(如您所用),然后使用匹配DataSeriesBodyType的模板,该模板不执行任何操作.

代码是:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


    <xsl:output method="xml" encoding="utf-8" indent="yes"/>

    <!-- Identity template : copy all text nodes,elements and attributes -->   
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>

    <!-- When matching DataSeriesBodyType: do nothing -->
    <xsl:template match="DataSeriesBodyType" />

</xsl:stylesheet>

如果要标准化输出删除空数据文本节点,请将以下模板添加到上一个样式表:

<xsl:template match="text()">
    <xsl:value-of select="normalize-space()" />
</xsl:template>
原文链接:https://www.f2er.com/xml/292695.html

猜你在找的XML相关文章