This is my XML Document(Small Snippt).
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p> <!-- Current Node -->
<w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
<w:r>
<w:t>
Paragraph1
</w:t>
</w:r>
</w:p>
<w:tbl>
<w:t>table info
</w:t>
</w:tbl>
<w:p>
<w:pPr>
</w:pPr>
<w:r>
<w:t>
Paragraph2
</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
</w:pPr>
<w:r>
<w:t>
Paragraph3
</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
<w:r>
<w:t>
Paragraph4
</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
</w:pPr>
<w:r>
<w:t>
Paragraph5
</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
<w:r>
<w:t>
Paragraph6
</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
Here, I want to select the following-sibling of the first<w:p> using for-each statement until it encounters the next<w:p> that having its <w:pPr><w:pStyle w:val="Heading1"/></w:pPr>.
for example,for first<w:p> i want to select only next three following-siblings.(ie,paragraph2,paragraph3 and including table info).because,4th <w:p> having <w:pPr><w:pStyle w:val="Heading1"/></w:pPr>.
The same case for 4th<w:p> if it is current node. Then i want to select only 5th <w:p>.
I dont know how to specify this condition in for-each.So, Can u guide me to get this…
My Required output is like:
<Document>
<Heading1>
<paragraph>paragrap1</paragraph>
<paragraph>table info</paragraph>
<paragraph>paragrap2</paragraph>
<paragraph>paragrap3</paragraph>
</Heading1>
<Heading1>
<paragraph>paragrap4</paragraph>
<paragraph>paragrap5</paragraph>
</Heading1>
<Heading1>
<paragraph>paragrap6</paragraph>
</Heading1>
</Document>
This XSLT 2.0 transformation shows one way of doing it using the XPAth 2.0 operator
>>:when applied on the provided XML document:
exactly the wanted nodes are selected and copied to the output:
Update: The OP has clarified what wanted the result of the transformation is (grouping), so here is:
I. XSLT 1.0 solution:
when this transformation is applied on the newly provided XML document:
the wanted, correct result is produced:
II. XSLT 2.0 solution:
when this XSLT 2.0 transformation is applied on the same XML document (above), the same wanted, correct result is produced: