Using XSLT, how can I wrap siblings that share the same value for an attribute.
Lets say I need to wrap a one or more <amendment/>
with the <chapter/>
they belong too.
From this:
<section>
<heading>some heading text</heading>
<amendment num='1' chapter='1'>
<foo/>
</amendment>
<amendment num='2' chapter='1'>
<bar/>
</amendment>
<amendment num='3' chapter='2'>
<baz/>
</amendment>
<heading>some heading text</heading>
<amendment num='4' chapter='3'>
<baz/>
</amendment>
</section>
into this:
<section>
<heading>some heading text</heading>
<chapter num="1">
<amendment num='1'>
<foo/>
</amendment>
<amendment num='2'>
<bar/>
</amendment>
</chapter>
<chapter num="2">
<amendment num='3'>
<baz/>
</amendment>
</chapter>
<heading>some heading text</heading>
<chapter num="3">
<amendment num='4'>
<baz/>
</amendment>
</chapter>
</section>
Note 1: Amendments are always listed sorted by chapter in the source XML.
Note 2: Im using PHP5 with XSLT 1.0