我有一些XML,我需要将父节点添加到node1,node2,node3等 . 然后我还需要与其他节点分组:
原始XML:
<parentnode>
<childnode attribute="option.a.b.1">
</childnode>
<childnode attribute="option.a.b.2">
</childnode>
<childnode attribute="option.a.b.1">
</childnode>
<childnode attribute="option.a.b.2">
</childnode>
<childnode attribute="option.a.b.3">
</childnode>
<childnode attribute="option.a.b.1">
</childnode>
<childnode attribute="option.a.b.2">
</childnode>
</parentnode>
期望的XML:
<parentnode>
<row0>
<childnode attribute="option.a.b.1">
</childnode>
<childnode attribute="option.a.b.2">
</childnode>
</row0>
<row1>
<childnode attribute="option.a.b.1">
</childnode>
<childnode attribute="option.a.b.2">
</childnode>
<childnode attribute="option.a.b.3">
</childnode>
</row1>
<row2>
<childnode attribute="option.a.b.1">
</childnode>
<childnode attribute="option.a.b.2">
</childnode>
</row2>
</parentnode>
option.a.b . * * *可以是任何数字,只要每次出现option.a.b.1,我都需要它来开始一个新行 . 我甚至不确定这是否可以在XSLT中使用?
2 回答
XSLT - 甚至XSLT 1.0 - 是一种图灵完备语言,所以是的,它是可能的 . 如果您使用的是XSLT 1.0,请尝试:
XSLT 1.0
Note :你可以通过调整我在这里给你的答案来解决这个问题:https://stackoverflow.com/a/26397156/3016153
假设你可以使用像Saxon 9或XmlPrime或AltovaXML这样的XSLT 2.0处理器
我故意不对行元素进行编号,因为如果你真的需要那么我的视图中会出现格式不佳的情况