-1

Below is the XML Structure.

<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>

The output, I am after is as follows-

<Title>Physics,#,Part 1 - 1,2,4</Title>
<Title>Physics,#,Part 2 - 2,3,4</Title>

I tried with various combinations using concat and string-join but all in vain :(

John
  • 2,820
  • 3
  • 30
  • 50

1 Answers1

0

Later at night, I played with it again and got the answer, though not the exact one I required, but will suffice my need -

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>
John
  • 2,820
  • 3
  • 30
  • 50