[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] indent XML doc based on spaces?
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|