|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: treeViewer
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
</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()" />'
<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="." />'
<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="." />'
<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>'
</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="." />'
<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="." />'
<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, '
')">
<xsl:call-template name="escape-ws">
<xsl:with-param name="text" select="substring-before($text, '
')" />
</xsl:call-template>
<xsl:text>\n</xsl:text>
<xsl:call-template name="escape-ws">
<xsl:with-param name="text" select="substring-after($text, '
')" />
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($text, '	')">
<xsl:value-of select="substring-before($text, '	')" />
<xsl:text>\t</xsl:text>
<xsl:call-template name="escape-ws">
<xsl:with-param name="text" select="substring-after($text, '	')" />
</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
|
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
|

Cart








