【发布时间】:2012-09-09 20:14:39
【问题描述】:
我需要过滤一些重复的节点中的操作(在一个键上) 以下是我的数据文件。
数据.xml
<root>
<node name="item1" />
<node name="item2" />
<node name="item3" />
<node name="item4" />
</root>
在文件 item1.xml 中
<item>
<group>A</group>
</item>
item2.xml
<item>
<group>B</group>
</item>
item3.xml
<item>
<group>B</group>
</item>
item4.xml
<item>
<group>D</group>
</item>
XSLT 文件
<xsl:for-each select="/root/node">
<xsl:variable name="itemName" select="@name"/>
<xsl:variable name="groupName" select="document($itemName)/item/group"/>
<xsl:value-of select="concat('Group ',$groupName)"/>
</xsl:for-each>
输出
A组 B组 B组 C组
期望的输出
A组 B组 C组
这里第 2 项和第 3 项根据它们的组属性属于同一组,所以我只需要打印其中任何一个的组名。
【问题讨论】:
-
我认为
<xsl:key>方法不能跨文档工作,但也许这就是答案的一部分。 -
@cbeer 如果我将属性放在单个文件中,可以做些什么吗?例如