This is XML Document.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
<w:r>
<w:t>Tables</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t>Table1</w:t>
</w:r>
</w:p>
<w:tbl>
<w:tr>
<w:tc>
<w:p>
<w:r>
<w:t>row1col1</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:p>
<w:r>
<w:t>row1col2</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:r>
<w:t>Table2</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>row11col12</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>
and i want to transform this xml document into below mentioned format using my xslt file.
<Document>
<Heading1>
<title>Tables</title>
<paragraph>Table1</paragraph>
<table>
<paragraph>row1col1</paragraph>
<paragraph>row1col2</paragraph>
<paragraph>row2col1</paragraph>
<paragraph>row2col2</paragraph>
</table>
<paragraph>Table2</paragraph>
<table>
<paragraph>row11col11</paragraph>
<paragraph>row11col12</paragraph>
<paragraph>row12col11</paragraph>
<paragraph>row12col12</paragraph>
</table>
</Heading1>
</Document>
This is my XSLT File for your reference…
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="html" indent="yes"/>
<xsl:template match="*">
<Document>
<xsl:variable name="headingName" select="(//w:body/w:p/w:pPr/w:pStyle[starts-with(@w:val, 'Heading')])[1]/@w:val"/>
<xsl:variable name="topLevelHeadings" select = "//w:body/w:p[w:pPr/w:pStyle/@w:val = $headingName]"/>
<xsl:choose>
<xsl:when test="$topLevelHeadings">
<xsl:apply-templates select="$topLevelHeadings">
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="//w:p[w:r[w:t]]">
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</Document>
</xsl:template>
<xsl:template match="w:p">
<Paragraph>
<xsl:apply-templates select="./w:r/w:t"/>
</Paragraph>
<xsl:apply-templates select="descendant::w:p">
</xsl:apply-templates>
</xsl:template>
<xsl:template match="w:t">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="//w:body/w:p[w:pPr[w:pStyle[starts-with(@w:val,'Heading')]]]">
<Heading1>
<Title>
<xsl:apply-templates select="./w:r/w:t"/>
</Title>
<xsl:choose>
<xsl:when test="following-sibling::w:tbl//w:p[w:r[w:t]]">
<xsl:for-each select="following-sibling::w:tbl">
<table>
<xsl:apply-templates select="descendant::w:p ">
</xsl:apply-templates>
</table>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="descendant::w:p">
<!-- | following-sibling::w:tbl//w:p[w:r[w:t]]-->
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="following-sibling::w:p[w:r and not(w:pPr[w:pStyle])] | following-sibling::w:p[w:r and not(w:pPr[w:pStyle[starts-with(@w:val,'Heading')]])]">
</xsl:apply-templates>
<xsl:variable name="nextHead" select="concat('Heading', number(substring-after('Heading1', 'Heading'))+1)"/>
<!-- Get a list of child nodes (headings) for the current node -->
<xsl:variable name="nextLevelHeadings" select="following-sibling::w:p[w:pPr[w:pStyle[@w:val=$nextHead]]]"/>
<!-- Apply recursively for next level headings within the scope -->
<xsl:apply-templates select="$nextLevelHeadings">
</xsl:apply-templates>
<!-- Close heading tag -->
</Heading1>
</xsl:template>
</xsl:stylesheet>
But the output is :
<Document>
<Heading1>
<Title>Table Manipulation</Title>
<table>
<paragraph>row1col1</paragraph>
<paragraph>row1col2</paragraph>
<paragraph>row2col1</paragraph>
<paragraph>row2col2</paragraph>
</table>
<table>
<paragraph>row11col11</paragraph>
<paragraph>row11col12</paragraph>
<paragraph>row12col11</paragraph>
<paragraph>row12col12</paragraph>
</table>
<Paragraph>Table1</Paragraph>
<Paragraph>Table2</Paragraph>
</Heading1>
</Document>
So, Please Guide me to get this issue and it will be work like my above said output requirement.Because, i want to transform this xml file without changing order of the paragraphs or tables.
Thanks & Regards,
p.saravanan
I have completed that task and thank you all for your co-operation in this…
i just attached modified xslt file that is working absolutley fine…