Thursday 30 May 2013

Transforming XML into MS Word Document using XSLT

XML Input:-

<?xml version="1.0" encoding="UTF-8"?>
<dradis>
    <notes>
        <note>
            <fields>
                <Title>Shekhawat</Title>
</fields>
        </note>
        <note>
            <fields>
                <Title>Vishnu</Title>
            </fields>
        </note>
        <note>
            <fields>
                <Title>Singh</Title>
            </fields>
        </note>
    </notes>
</dradis>

XSLT Script:-

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
       
        <xsl:processing-instruction name="mso-application">
            <xsl:text>progid="Word.Document"</xsl:text>
        </xsl:processing-instruction>
        <w:wordDocument
            xmlns:w="http://schemas.microsoft.com/office/word/2007/wordml">           
            <w:body>               
        <xsl:for-each select="dradis/notes/note/fields">
                    <w:p>
                        <w:r>
                            <w:t><xsl:value-of select="Title"/></w:t>
                        </w:r>
                        </w:p>
                </xsl:for-each>
            </w:body>
        </w:wordDocument>       
    </xsl:template>
</xsl:stylesheet>



No comments: