Subject: Re: indent XML doc based on spaces? From: "Nikolai Grigoriev" <grig@xxxxxxxxxxx> Date: Thu, 5 Oct 2000 12:15:54 +0400 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: indent XML doc based on spaces?, Eric van der Vlist | Thread | Re: indent XML doc based on spaces?, mnaughto |
Re: your mail, T.Pospisek's MailLis | Date | RE: XSL attribute expression, Kay Michael |
Month |