【发布时间】:2014-01-23 22:31:13
【问题描述】:
我有一个这样的传入 XML:
<comm>
<source id ="1">TV</source>
<source id ="2">Radio</source>
<source id ="3">TV</source>
<source id ="4">Computer</source>
</comm>
我需要一个 XSLT 来制作像这样的输出 XML:
<comm>
<type id ="1">TV</source>
<type id ="2">Radio</source>
<type id ="4">Computer</source>
</comm>
基本上我希望 XSLT 遍历每个 <source> 元素并创建一个 <type> 元素。但是如果<type> 元素的值已经存在,XSLT 将跳过创建该元素。
例如,如果您查看传入的 XML,则“TV”值出现两次;所以 XSLT 只会用 TV 值创建元素一次。
我很难弄清楚这一点。我正在使用 XSLT 2.0。
我尝试通过动态更新变量然后删除重复值来做到这一点。但是 XSLT 不能改变变量。
【问题讨论】:
-
XSLT Removing duplicates 的可能重复项