假设我有以下 XML:
<root>
<tokens>
<token ID="t1">blah</token>
<token ID="t2">blabla</token>
<token ID="t3">shovel</token>
</tokens>
<relatedStuff>
<group gID="s1">
<references tokID="t1"/>
<references tokID="t2"/>
</group>
<group gID="s2">
<references tokID="t3"/>
</group>
</relatedStuff>
</root>
现在,考虑到每个标记的 for-each 循环效率很低而且是个坏主意,如何使用模板匹配将这个 xml 转换为以下内容?
<s id="everything_merged">
<tok id="t1" gID="s1" >blah</tok>
<tok id="t2" gID="s1" >blabla</tok>
<tok id="t3" gID="s2" >shovel</tok>
</s>
我想要的<s>
只是“gID”,即与<tokens>
.
<xsl:for-each select="b:root/a:tokens/a:token">
<!-- and here some template matching -->
<xsl:attribute name="gID">
<xsl:value-of select="--correspondingNode's--@gID"/>
</xsl:attribute>
</xsl:for-each>
我对这种事情很模糊,所以非常感谢你的帮助!