JavaRanch Home    
 
This page:         last edited 16 September 2007         What's Changed?         Edit

How To Pretty Print Xml With Xsl   

This is how: Note(s) - Have only tried this with xalan.


<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xalan="http://xml.apache.org/xslt">

    <xsl:output method="xml" encoding="UTF-8" indent="yes" xalan:indent-amount="2"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="*">
        <xsl:copy>
            <xsl:copy-of select="@*" />
            <xsl:apply-templates />
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

This doesn't support CDATA.


XmlFaq CategoryCodeSamples

JavaRanchContact us — Copyright © 1998-2014 Paul Wheaton