【发布时间】:2011-01-17 07:50:08
【问题描述】:
<root>
<element>
<id>1</id>
<group>first</group>
</element>
<element>
<id>2</id>
<group>second</group>
</element>
<element>
<id>3</id>
<group>first</group>
</element>
...
<root>
如何在 xslt 1.0 中按组名对元素进行分组。 输出:
<root>
<group name="first">
<element>
<id>1</id>
<group>first</group>
</element>
<element>
<id>3</id>
<group>first</group>
</element>
</group>
<group name="second">
<element>
<id>2</id>
<group>second</group>
</element>
</group>
</root>
有什么想法吗?
【问题讨论】:
-
顺便说一句,您的 xml 无效
first -
仍然无效
first :) -
好问题,+1。请参阅我的答案以获得比当前接受的解决方案和要点的解释更短的内容。 :)
-
还添加了 XSLT 2.0 解决方案。 :)