以下是XML结构。
<Docs>
<Doc>
<Title>Physics</Title>
<Desc>
<Part n="Part 1">
<Chap c="1"/>
<Chap c="2"/>
<Chap c="4"/>
</Part>
</Desc>
</Doc>
<Doc>
<Title>Physics</Title>
<Desc>
<Part n="Part 2">
<Chap c="2"/>
<Chap c="3"/>
<Chap c="4"/>
</Part>
</Desc>
</Doc>
</Docs>
我输出的输出如下 -
<Title>Physics,#,Part 1 - 1,2,4</Title>
<Title>Physics,#,Part 2 - 2,3,4</Title>
我尝试使用concat
和string-join
进行各种组合,但都是徒劳的:(
答案 0 :(得分:0)
晚上,我再次玩它并得到答案,虽然不是我要求的确切答案,但足以满足我的需要 -
let $a :=
<Docs>
<Doc>
<Title>Physics</Title>
<Desc>
<Part n="Part 1">
<Chap c="1"/>
<Chap c="2"/>
<Chap c="4"/>
</Part>
</Desc>
</Doc>
<Doc>
<Title>Physics</Title>
<Desc>
<Part n="Part 2">
<Chap c="2"/>
<Chap c="3"/>
<Chap c="4"/>
</Part>
</Desc>
</Doc>
</Docs>
for $x in $a//Doc
return
<Title>{
concat($x/Title,"#",
string-join(
($x/Desc/Part/@n, " - ", string-join(($x/Desc/Part/Chap/@c, ""),",")),""))
}</Title>