Re: indent XML doc based on spaces?

Subject: Re: indent XML doc based on spaces?
From: "Nikolai Grigoriev" <grig@xxxxxxxxxxx>
Date: Thu, 5 Oct 2000 12:15:54 +0400

> Has anyone built an XSLT transform that indents an XML file based on spaces
> (e.g. 3 spaces per level)?  I'm just confusing myself here.  The closest I
> have come is modifying the identity transform to be as included below:

Try the following code. It differs only slightly from yours, yet indents both
starting and closing tags and has no limits on element nesting depth.


<xsl:stylesheet version="1.0" xmlns:xsl="";>
<xsl:output method="xml"/>
<xsl:param name="indent-increment" select="'   '" />

<xsl:template match="*">
   <xsl:param name="indent" select="'&#xA;'"/>

   <xsl:value-of select="$indent"/>
     <xsl:copy-of select="@*" />
       <xsl:with-param name="indent"
            select="concat($indent, $indent-increment)"/>
     <xsl:value-of select="$indent"/>

<xsl:template match="comment()|processing-instruction()">
   <xsl:copy />

<!-- WARNING: this is dangerous. Handle with care -->
<xsl:template match="text()[normalize-space(.)='']"/>


 XSL-List info and archive:

Current Thread