我尝试过使用 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>
我需要的是对同一位置下的Block
s 和s 进行分组,并删除重复的位置编号。House
例如它会变成这样:
<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>
。