This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: indent XML doc based on spaces?
- To: "'xsl-list at mulberrytech dot com'" <xsl-list at mulberrytech dot com>
- Subject: RE: indent XML doc based on spaces?
- From: Joshua Allen <joshuaa at microsoft dot com>
- Date: Sat, 7 Oct 2000 18:51:27 -0700
- Reply-To: xsl-list at mulberrytech dot com
FYI, I used the sample supplied by Nikolai and have updated the tool with
that. Also thanks to Eric and Martin for help in figuring out what I was
doing wrong. So now the tool has pretty formatting, remembers last working
directory, and allows you to test XPath expression in addition to the other
new features.
Thanks!
> -----Original Message-----
> From: Nikolai Grigoriev [mailto:grig@renderx.com]
> Sent: Thursday, October 05, 2000 1:16 AM
> To: XSL List
> Subject: Re: indent XML doc based on spaces?
>
>
> Joshua,
>
> > 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.
>
> Regards,
> Nikolai
>
> ===========================
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml"/>
> <xsl:param name="indent-increment" select="' '" />
>
> <xsl:template match="*">
> <xsl:param name="indent" select="'
'"/>
>
> <xsl:value-of select="$indent"/>
> <xsl:copy>
> <xsl:copy-of select="@*" />
> <xsl:apply-templates>
> <xsl:with-param name="indent"
> select="concat($indent, $indent-increment)"/>
> </xsl:apply-templates>
> <xsl:value-of select="$indent"/>
> </xsl:copy>
> </xsl:template>
>
> <xsl:template match="comment()|processing-instruction()">
> <xsl:copy />
> </xsl:template>
>
> <!-- WARNING: this is dangerous. Handle with care -->
> <xsl:template match="text()[normalize-space(.)='']"/>
>
> </xsl:stylesheet>
>
>
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list