【发布时间】:2013-05-14 21:11:02
【问题描述】:
我尝试过使用 XSLT 1.0 对 XML 进行简单的分组,并且成功了,但在这里我遇到了一些更复杂且实际上不同的情况。 所以XML结构基本上是这样的:
<Main>
<TB>
--> some elements and stuff - not relevant
<City>
<Area>
<Position>5</Position>
<House>
--> some elements and stuff
</House>
</Area>
<Area>
<Position>5</Position>
<Block>
--> some elements and stuff
</Block>
</Area>
<Area>
<Position>6</Position>
<House>
--> some elements and stuff
</House>
</Area>
<Area>
<Position>6</Position>
<Block>
--> some elements and stuff
</Block>
</Area>
</City>
<City>
--> same structure but with several repetitions of Position 7 and 8.
</City>
</TB>
</Main>
我需要将位于同一位置的Blocks 和Houses 分组,并删除重复的位置编号。例如它会变成这样:
<City>
<Area>
<Position>5</Position>
<House>
--> some elements and stuff
</House>
<Block>
--> some elements and stuff
</Block>
</Area>
<Area>
<Position>6</Position>
<House>
--> some elements and stuff
</House>
<Block>
--> some elements and stuff
</Block>
</Area>
</City>
<City>
--> same structure for Position 7 and 8.
</City>
比较难,因为Position不是Area的一个属性,所以我基本上要确定Area的Position的值,然后抓取同一个Position下的House和Block,放在一起被包围相同的<Area> </Area>。
【问题讨论】:
标签: xml xslt xslt-1.0 xslt-grouping muenchian-grouping