This is my Xml file.i want to transform this xml file into another customized xml file by using xslt.
XML FILE:
<?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:r>
<w:t>Text1-</w:t>
</w:r>
<w:smartTag>
<w:smartTag>
<w:smartTag>
<w:smartTag>
<w:r>
<w:t>Text2-</w:t>
</w:r>
</w:smartTag>
</w:smartTag>
<w:r>
<w:t>Text3-</w:t>
</w:r>
<w:smartTag>
<w:r>
<w:t>Text4-</w:t>
</w:r>
</w:smartTag>
<w:r>
<w:t>Text5-</w:t>
</w:r>
</w:smartTag>
</w:smartTag>
<w:r>
<w:t>Text6-</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
and MY XSLT Snippt is :
<?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">
<xsl:output method="html" indent="yes"/>
<xsl:template match="*">
<Document>
<xsl:choose>
<xsl:apply-templates select="//w:p[w:r[w:t]]">
</xsl:apply-templates>
</xsl:choose>
</Document>
</xsl:template>
<xsl:template match="w:p">
<Paragraph>
<xsl:if test="(.//w:smartTag/w:r/w:t)">
<xsl:apply-templates select="//w:smartTag//w:r//w:t"/>
</xsl:if>
<xsl:apply-templates select="./w:r/w:t"/>
</Paragraph>
</xsl:template>
<xsl:template match="w:t">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
My Current Output is :
<Document>
<Paragraph>
Text2-Text3-Text4-Text5-Text1-Text6-
</Paragraph>
</Document>
My Required Output is :
<Document>
<Paragraph>
Text1-Text2-Text3-Text4-Text5-Text6-
</Paragraph>
</Document>
Please Guide me to get the elements without losing the order it preserves…
Unless you have some extra rules about what should be processed, this could done quite simply by having a template to match w:t elements
You would also need matchs to handle the document and paragraph. Try the following XML
When applied to your sample XML, the following is output