I have xml which contain some documents:
<document>
<line id="0">
<field id="0"><![CDATA[H:doc1]]></field>
</line>
<line id="1">
<field id="0"><![CDATA[L:1]]></field>
</line>
<line id="2">
<field id="0"><![CDATA[L:2]]></field>
</line>
<line id="3">
<field id="0"><![CDATA[L:3]]></field>
</line>
<line id="4">
<field id="0"><![CDATA[H:doc2]]></field>
</line>
<line id="5">
<field id="0"><![CDATA[L:1]]></field>
</line>
</document>
H=header of document and L=Line-item. in this example whe have two H that means two documents which number doc1 and doc2. doc1 have three line items and doc2 have one line item.
how to convert data using xslt version 1 to get this result:
<documents>
<document>
<header>
<number>doc1</number>
</header>
<line-item>
<line-number>1</line-number>
<line-number>2</line-number>
<line-number>3</line-number>
</line-item>
</document>
<document>
<header>
<number>doc2</number>
</header>
<line-item>
<line-number>1</line-number>
</line-item>
</document>
</documents>
This XSLT 1.0 transformation:
when applied on the provided XML document:
produces the wanted, correct result:
Explanation: Using keys to conveniently specify and select the complete group of adjacent “lines” following a “header”.