xsl-list
[Top] [All Lists]

Problem with modified "Pretty XML Tree Viewer "(by Mike Brown and Jeni Tennison)

2004-03-31 00:39:27
Hi,

I modified (more precise: stripped down) the "Pretty XML Tree Viewer 1.0" from Mike J. Brown and Jeni Tennison for my needs.
Now I have two questions:

1. Here my modified tree-view.xsl:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:output method="html" indent="no"/>
        <xsl:variable name="apos">'</xsl:variable>
        <xsl:template match="/">
                <html>
                        <head>
                                <title>Supertable</title>
                                <style type="text/css">
body { font-family: sans-serif; font-size: 80%; background-color: #EAEAD9; color: black }
                                        .connector              { font-family: 
monospace; }
.name { color: navy; background-color: white; text-decoration: underline; font-weight: bold; padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px }
                                        .altname                { color: navy; 
text-decoration: underline }
                                        .uri                            { 
color: #444; font-style: italic }
                                        .value                  { color: #040; 
background-color: #CCC; font-weight: bold }
                                        .escape                 { color: #620; 
font-family: monospace }

                                        .root                   { color: 
yellow; background-color: black }
                                        .element                { color: 
yellow; background-color: navy }
                                        .namespace      { color: yellow; 
background-color: #333 }
                                        .attribute              { color: 
yellow; background-color: #040 }
                                        .text                           { 
color: yellow; background-color: #400 }
                                        .pi                             { 
color: yellow; background-color: #044 }
                                        .comment                { color: 
yellow; background-color: #303 }
                                        
.root,.element,.attribute,.namespace,.text,.comment,.pi
{ font-weight: bold; padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px }
                                </style>
                        </head>
                        <body>
                                <h3>tree-view.xsl output</h3>
                                <xsl:apply-templates select="." mode="render"/>
                        </body>
                </html>
        </xsl:template>
        <xsl:template match="/" mode="render">
                <span class="root">root</span>
                <br/>
                <xsl:apply-templates mode="render"/>
        </xsl:template>
        <xsl:template match="*" mode="render">
                <xsl:call-template name="ascii-art-hierarchy"/>
                <br/>
                <xsl:call-template name="ascii-art-hierarchy"/>
                <span class="connector">___</span>
                <span class="element">Tabelle</span>
                <xsl:text>&#160;</xsl:text>
                <span class="name">
                        <xsl:value-of select="local-name()"/>
                </span>
                <br/>
                <xsl:apply-templates select="@*" mode="render"/>
                <xsl:apply-templates mode="render"/>
        </xsl:template>
        <xsl:template match="@*" mode="render">
                <xsl:call-template name="ascii-art-hierarchy"/>
                <span class="connector">&#160;&#160;</span>
                <span class="connector">\___</span>
                <span class="attribute">attribute</span>
                <xsl:text>&#160;</xsl:text>
                <span class="name">
                        <xsl:value-of select="local-name()"/>
                </span>
                <xsl:text> = </xsl:text>
                <span class="value">
                        <!-- make spaces be non-breaking spaces, since this is 
HTML -->
                        <xsl:call-template name="escape-ws">
                                <xsl:with-param name="text" select="translate(.,' 
','&#160;')"/>
                        </xsl:call-template>
                </span>
                <br/>
        </xsl:template>
        <xsl:template match="processing-instruction()" mode="render">
                <xsl:call-template name="ascii-art-hierarchy"/>
                <br/>
                <xsl:call-template name="ascii-art-hierarchy"/>
                <span class="connector">___</span>
                <span class="pi">processing instruction</span>
                <xsl:text>&#160;</xsl:text>
                <xsl:text>target=</xsl:text>
                <span class="value">
                        <xsl:value-of select="name()"/>
                </span>
                <xsl:text>&#160;instruction=</xsl:text>
                <span class="value">
                        <xsl:value-of select="."/>
                </span>
                <br/>
        </xsl:template>
        <xsl:template name="ascii-art-hierarchy">
                <xsl:for-each select="ancestor::*">
                        <xsl:choose>
                                <xsl:when test="following-sibling::node()">
<span class="connector">&#160;&#160;</span>|<span class="connector">&#160;&#160;</span>
                                        <xsl:text>&#160;</xsl:text>
                                </xsl:when>
                                <xsl:otherwise>
                                        <span 
class="connector">&#160;&#160;&#160;&#160;</span>
                                        <span 
class="connector">&#160;&#160;</span>
                                </xsl:otherwise>
                        </xsl:choose>
                </xsl:for-each>
                <xsl:choose>
                        <xsl:when test="parent::node() and ../child::node()">
                                <span class="connector">&#160;&#160;</span>
                                <xsl:text>|</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                                <span 
class="connector">&#160;&#160;&#160;</span>
                        </xsl:otherwise>
                </xsl:choose>
        </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>
                                <!-- <span class="escape">\n</span> -->
                                <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;')"/>
                                <!-- <span class="escape">\t</span> -->
                                <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>
</xsl:stylesheet>


My problem is, that the "|" in the output are present, even if the nodes got no following-nodes.
I tried out some logic to avoid this, but I couldn't solve the problem.


E.g. I'll get this html-output:

       |___Tabelle hallo
       |     |
       |     |___Tabelle Se
       |     |     |
       |     |     |___Tabelle Serve
       |     |
       |     |___Tabelle Yo


But I want to get this html-output:


       |___Tabelle hallo
             |
             |___Tabelle Se
             |     |
             |     |___Tabelle Serve
             |
             |___Tabelle Yo


2. Is there a newer version of this great ""Pretty XML Tree Viewer"?

Thanks
Jonny

_________________________________________________________________
E-Mails sind Ihnen nicht schnell genug? http://www.msn.de/messenger MSN Messenger - Kommunikation in Echtzeit



<Prev in Thread] Current Thread [Next in Thread>
  • Problem with modified "Pretty XML Tree Viewer "(by Mike Brown and Jeni Tennison), Jonny Pony <=