xml – XSLT复制除1个元素之外的所有节点
发布时间:2020-12-16 07:51:04 所属栏目:百科 来源:网络整理
导读:events main actionmodification/action subActionweights/subAction /main/eventsSeriesSet Series id="Price_0" seriesBodies SeriesBody DataSeriesBodyTypeDo Not Copy/DataSeriesBodyType /SeriesBody /SeriesBodies /Series/SeriesSet 如何复制所有xml
<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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |