[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

indent XML doc based on spaces?

Subject: indent XML doc based on spaces?
From: Joshua Allen <joshuaa@xxxxxxxxxxxxx>
Date: Wed, 4 Oct 2000 22:55:17 -0700
transform indent xml
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:

Problem is, this indents only opening tags, not closing tags, and doesn't
remove any indents that might already be in the source document.

P.S.  The reason I'm doing this is so I can include a file (pretty.xslt)
with my XSLT test tool and allow pretty (indented but not different infoset)
formatting of the text.  I could write some code to do it, but if it can be
done as an external XSLT file it makes things easier to customize.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />
<xsl:variable name="indent" select="3" />
<xsl:variable name="spaces" select="'                 '" />

<xsl:template match="*">
   <xsl:value-of select="substring($spaces,1,count(ancestor::node()) *
$indent)" />
   <xsl:copy>
      <xsl:copy-of select="@*" />
      <xsl:apply-templates />
   </xsl:copy>
</xsl:template>

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

</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.