Reputation: 11592
This is my xml document.
<w:document xmlns:w="w">
<w:body>
<w:p>
<w:pPr><w:pStyle w:val="Heading1"/></w:pPr>
<w:r><w:t>Tables</w:t></w:r> <!-- Assume Current Node here -->
</w:p>
<w:tbl>
<w:tr>
<w:tc>
<w:p>
<w:r><w:t>row1col</w:t></w:r>
</w:p>
</w:tc>
<w:tc>
<w:p>
<w:r><w:t>row1co2</w:t></w:r>
</w:p>
</w:tc>
</w:tr>
<w:tr>
<w:tc>
<w:p>
<w:r><w:t>row2col1</w:t></w:r>
</w:p>
</w:tc>
<w:tc>
<w:p>
<w:r><w:t>row2col2</w:t></w:r>
</w:p>
</w:tc>
</w:tr>
</w:tbl>
<w:p>
<w:pPr><w:pStyle w:val="Normal"/></w:pPr>
<w:r><w:t>2nd table</w:t></w:r>
</w:p>
<w:tbl>
<w:tr>
<w:tc>
<w:p>
<w:r><w:t>row11col11</w:t></w:r>
</w:p>
</w:tc>
<w:tc>
<w:p>
<w:r><w:t>row11co12</w:t></w:r>
</w:p>
</w:tc>
</w:tr>
<w:tr>
<w:tc>
<w:p>
<w:r><w:t>row12col11</w:t></w:r>
</w:p>
</w:tc>
<w:tc>
<w:p>
<w:r><w:t>row12col12</w:t></w:r>
</w:p>
</w:tc>
</w:tr>
</w:tbl>
</w:body>
</w:document>
So, I want to transform this xml file to given format.
<Document>
<Heading1>
<title>Tables</title>
<table>
<paragraph>row1col1</paragraph>
<paragraph>row1col2</paragraph>
<paragraph>row2col1</paragraph>
<paragraph>row2col2</paragraph>
</table>
<paragraph>2nd Table</paragraph>
<table>
<paragraph>row11col11</paragraph>
<paragraph>row11col12</paragraph>
<paragraph>row12col11</paragraph>
<paragraph>row12col12</paragraph>
</table>
</Heading1>
</Document>
I have done almost done everything except below mentioned case.Assume now current node is first <w:p>
(Mentioned in xml Document).So, for getting table items, i coded like
<xsl:choose>
<xsl:when test="following-sibling::w:tbl//w:p[w:r[w:t]]" >
<table>
<!--some code here -->
</table>
</xsl:when>
</xsl:choose>
but, while doing so, the output is like...
<table>
<paragraph>row1col1</paragraph>
<paragraph>row1col2</paragraph>
<paragraph>row2col1</paragraph>
<paragraph>row2col2</paragraph>
<paragraph>row11col11</paragraph>
<paragraph>row11col12</paragraph>
<paragraph>row12col11</paragraph>
<paragraph>row12col12</paragraph>
</table>
I want to group each and every table in separate table node.How i do it? Please Guide me to get out of this issue...
Upvotes: 0
Views: 628
Reputation: 70618
From the comment in your XSLT, it suggests you are positioned on the w:r element, but your XSLT snippet suggests you are actually positioned on the w:p element.
Assuming your current node is w:p if you want to get the first w:tbl element that follows it, you can do the following
<xsl:when test="following-sibling::w:tbl[1]//w:p[w:r[w:t]]" >
However, it sounds like you only want to find the first w:tbl element if it immediately follows the w:p (i.e the first element that follows the w:p is the w:tbl element). In this case, you probably want to do the following
<xsl:when test="following-sibling::*[1][self::w:tbl]//w:p[w:r[w:t]]" >
Upvotes: 2