【发布时间】:2013-03-21 15:33:58
【问题描述】:
我在使用 XSLT V1.0 删除重复节点时遇到问题。我有这个入口
<?xml version="1.0" encoding="utf-8"?>
<myRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Mappings>
<Mapping fieldName="field1" >
</Mapping>
<Mapping fieldName="field1">
</Mapping>
<Mapping fieldName="field2" >
</Mapping>
<Mapping fieldName="field3" >
</Mapping>
<Mapping fieldName="field4">
</Mapping>
</Mappings>
</myRoot>
我有这个 XSL 文件
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Mappings">
<xsl:if test="not(following::Mappings[Mapping/@fieldName=current()/Mapping/@fieldName])">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
我有与结果相同的条目 XML 文件!
我怎样才能摆脱重复的节点()?
我尝试了一切,但没有结果:(
我试过了 Removing duplicates in xml with xslt Transform to remove duplicate and copy rest Removing consecutive duplicates with XSLT XSLT 1.0 textlist to individual elements and duplicate removal
......
我应该怎么做才能得到这个结果??
<?xml version="1.0" encoding="utf-8"?>
<myRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Mappings>
<Mapping fieldName="field1">
</Mapping>
<Mapping fieldName="field2" >
</Mapping>
<Mapping fieldName="field3" >
</Mapping>
<Mapping fieldName="field4">
</Mapping>
</Mappings>
</myRoot>
谢谢
【问题讨论】:
-
在我回答问题 18 分钟后,您似乎对问题进行了编辑。我的回答有什么不满意的地方吗?如果您需要像这样分隔元素的标签,可以这样做,但我的答案中的输出在语义上与您那里的输出相同。