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

Re: treeViewer

Subject: Re: treeViewer
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 13 Feb 2001 10:55:35 +0000
ascii art instructions
Hi Mike,

> I really want to do like what someone else was asking about on the list
> here recently.. ASCII art versions just like I normally do by hand in my
> posts:

Here you are.  I thought you'd probably want any whitespace to be
escaped with \n and \t, and whitespace to be stripped (easy to take
that instruction out if you don't).  I've also made it go from the
root node rather than an element, though that could be changed.

<xsl:output method="text" />

<xsl:strip-space elements="*" />

<xsl:template match="/">
   <xsl:apply-templates select="." mode="ascii-art" />
</xsl:template>

<xsl:template match="/" mode="ascii-art">
   <xsl:text>root&#xA;</xsl:text>
   <xsl:apply-templates mode="ascii-art" />
</xsl:template>

<xsl:template match="*" mode="ascii-art">
   <xsl:call-template name="ascii-art-hierarchy" />
   <xsl:text />___element '<xsl:value-of select="name()" />'&#xA;<xsl:text />
   <xsl:apply-templates select="@*" mode="ascii-art" />
   <xsl:for-each select="namespace::*">
      <xsl:call-template name="ascii-art-hierarchy" />
      <xsl:text />  \___namespace '<xsl:value-of select="name()" />' = '<xsl:value-of select="." />'&#xA;<xsl:text />
   </xsl:for-each>
   <xsl:apply-templates mode="ascii-art" />
</xsl:template>

<xsl:template match="@*" mode="ascii-art">
   <xsl:call-template name="ascii-art-hierarchy" />
   <xsl:text />  \___attribute '<xsl:value-of select="name()" />' = '<xsl:value-of select="." />'&#xA;<xsl:text />
</xsl:template>

<xsl:template match="text()" mode="ascii-art">
   <xsl:call-template name="ascii-art-hierarchy" />
   <xsl:text>___text '</xsl:text>
   <xsl:call-template name="escape-ws">
      <xsl:with-param name="text" select="." />
   </xsl:call-template>
   <xsl:text>'&#xA;</xsl:text>
</xsl:template>

<xsl:template match="comment()" mode="ascii-art">
   <xsl:call-template name="ascii-art-hierarchy" />
   <xsl:text />___comment '<xsl:value-of select="." />'&#xA;<xsl:text />
</xsl:template>

<xsl:template match="processing-instruction()" mode="ascii-art">
   <xsl:call-template name="ascii-art-hierarchy" />
   <xsl:text />___processing-instruction '<xsl:value-of select="name()" />' = '<xsl:value-of select="." />'&#xA;<xsl:text />
</xsl:template>

<xsl:template name="ascii-art-hierarchy">
   <xsl:for-each select="ancestor::*">
      <xsl:choose>
         <xsl:when test="following-sibling::node()">  |   </xsl:when>
         <xsl:otherwise><xsl:text>      </xsl:text></xsl:otherwise>
      </xsl:choose>
   </xsl:for-each>
   <xsl:if test="parent::node()">  |</xsl:if>
</xsl:template>

<xsl:template name="escape-ws">
   <xsl:param name="text" />
   <xsl:choose>
      <xsl:when test="contains($text, '&#xA;')">
         <xsl:call-template name="escape-ws">
            <xsl:with-param name="text" select="substring-before($text, '&#xA;')" />
         </xsl:call-template>
         <xsl:text>\n</xsl:text>
         <xsl:call-template name="escape-ws">
            <xsl:with-param name="text" select="substring-after($text, '&#xA;')" />
         </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($text, '&#x9;')">
         <xsl:value-of select="substring-before($text, '&#x9;')" />
         <xsl:text>\t</xsl:text>
         <xsl:call-template name="escape-ws">
            <xsl:with-param name="text" select="substring-after($text, '&#x9;')" />
         </xsl:call-template>
      </xsl:when>
      <xsl:otherwise><xsl:value-of select="$text" /></xsl:otherwise>
   </xsl:choose>
</xsl:template>


I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Current Thread
  • treeViewer, (continued)
      • Tobias Reif - Sat, 10 Feb 2001 08:27:05 -0500 (EST)
        • Jiri Jirat - Mon, 12 Feb 2001 02:52:18 -0500 (EST)
        • Tobias Reif - Mon, 12 Feb 2001 06:28:34 -0500 (EST)
        • Mike Brown - Mon, 12 Feb 2001 15:54:57 -0500 (EST)
        • Jeni Tennison - Tue, 13 Feb 2001 06:25:14 -0500 (EST) <=
        • Mike Brown - Tue, 13 Feb 2001 10:52:05 -0500 (EST)
      • David Carlisle - Sat, 10 Feb 2001 08:44:55 -0500 (EST)

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.