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

Re: indent XML doc based on spaces?

Subject: Re: indent XML doc based on spaces?
From: mnaughto@xxxxxxxxxxx
Date: Thu, 5 Oct 2000 09:54:44 +0100
span style indent
Hi Joshua,

I didn't check your algorithm, but here is a stylesheet I use to display
colour-coded and indented XML, in case it provides useful ideas.

Having set the FONT to Courier, it achieves the indenting at each level with
this HTML technique:
<DIV STYLE="margin-left:1em;">

This version uses the obsolete IE5 XSL namespace.

If this is useful, I can't claim the credit - I didn't write this stylesheet...

Anyway, here's the code:

<?xml version="1.0"?>

<!-- Generic stylesheet for viewing XML -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  <!-- This template will always be executed, even if this stylesheet is not run
 on the document root -->
  <xsl:template>
    <DIV STYLE="font-family:Courier; font-size:10pt; margin-bottom:2em">
      <!-- Scoped templates are used so they don't interfere with the "kick-off"
 template. -->
      <xsl:apply-templates select=".">
        <xsl:template><xsl:apply-templates/></xsl:template>

        <xsl:template match="*">
          <DIV STYLE="margin-left:1em; color:gray">
            &lt;<xsl:node-name/><xsl:apply-templates select="@*"/>/&gt;
          </DIV>
        </xsl:template>

        <xsl:template match="*[node()]">
          <DIV STYLE="margin-left:1em">
            <SPAN STYLE="color:gray">&lt;<xsl:node-name/><xsl:apply-templates
select="@*"/>&gt;</SPAN><xsl:apply-templates select="node()"/><SPAN
STYLE="color:gray">&lt;/<xsl:node-name/>&gt;</SPAN>
          </DIV>
        </xsl:template>

        <xsl:template match="@*">
          <SPAN STYLE="color:navy"> <xsl:node-name/>="<SPAN
STYLE="color:black"><xsl:value-of /></SPAN>"</SPAN>
        </xsl:template>

        <xsl:template match="pi()">
          <DIV STYLE="margin-left:1em;
color:maroon">&lt;?<xsl:node-name/><xsl:apply-templates select="@*"/>?&gt;</DIV>
        </xsl:template>

        <xsl:template match="cdata()"><pre>&lt;![CDATA[<xsl:value-of
/>]]&gt;</pre></xsl:template>

        <xsl:template match="textNode()"><xsl:value-of /></xsl:template>
      </xsl:apply-templates>
    </DIV>
  </xsl:template>
</xsl:stylesheet>


Thanks,
Martin



 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.