|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: navigating through recursive defined tree
There are probably smarter ways of doing it, but for a demo I hacked
together recently, I used a technique like what I show below.
At the moment I'm studying the default stylesheet that IE5 uses
to render XML in the browser because it is a showcase example
of using almost every supported feature of XSL to build a sophisticated
rendering.
My (more simpleton) technique looked like...
Considering an XML document like:
<?xml version="1.0" ?>
<?xml:stylesheet type="text/xsl" href="tree.xsl" ?>
<tree title="Your Itinerary">
<node icon="itinerary.gif" id="1" title="1" open="Y">
<node icon="flight.gif" id="2" title="1.1" open="Y"/>
<node icon="flight.gif" id="3" title="1.2" open="Y"/>
<node icon="city.gif" id="4" title="1.3" open="N">
<node icon="flight.gif" id="5" title="1.3.1" open="Y"/>
<node icon="city.gif" id="6" title="1.3.2" open="Y"/>
</node>
<node icon="flight.gif" id="7" title="2.1" open="Y">
<node icon="flight.gif" id="8" title="2.1.1" open="N">
<node icon="flight.gif" id="12" title="2.1.1.1" open="N"/>
<node icon="flight.gif" id="13" title="2.1.1.2" open="N"/>
<node icon="flight.gif" id="14" title="2.1.1.3" open="N"/>
</node>
<node icon="city.gif" id="9" title="2.1.2" open="N"/>
</node>
<node icon="flight.gif" id="10" title="2.2" open="Y"/>
<node icon="flight.gif" id="11" title="2.3" open="Y"/>
</node>
</tree>
I used the following stylesheet to format an HTML tree (not using DIV's,
but you could extend to use a different technique for the tree that
did use DIV's). The technique I was using for the tree is just using
a "Stretchable" 1x1-pixel gif and <BR> tags so it works on any browser...
The "plus.gif", "minus.gif" and "nothing.gif" are little gifs that look
like the plus sign, minus sign, and leaf node of the Windows Explorer.
The end result of browsing tree.xml, looks like this:
http://www.geocities.com/~smuench/xsl-dev1.gif
Here's the code...
<?xml version="1.0" ?>
<!-- This XSL Stylesheet that transforms <NODE>'s into a DHTML Tree -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template>
<xsl:apply-templates match="tree"/>
</xsl:template>
<xsl:template match="tree">
<xsl:apply-templates match="node"/>
</xsl:template>
<xsl:template match="node[@open = 'N']">
<img align="absmiddle" src="s.gif" height="1">
<xsl:attribute name="width">
<xsl:eval>(depth(this)-1)*24</xsl:eval>
</xsl:attribute>
</img>
<img align="absmiddle">
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="src">
<xsl:eval>
this.firstChild == null ? "nothing.gif" : this.getAttribute("open") ==
"Y" ? "minus.gif" : "plus.gif"
</xsl:eval>
</xsl:attribute>
</img>
<img align="absmiddle">
<xsl:attribute name="src"><xsl:value-of select="@icon"/></xsl:attribute>
</img>
<xsl:value-of select="@title"/>
<BR/>
</xsl:template>
<xsl:template match="node[@open = 'Y']">
<img align="absmiddle" src="s.gif" height="1">
<xsl:attribute name="width">
<xsl:eval>(depth(this)-1)*24</xsl:eval>
</xsl:attribute>
</img>
<img align="absmiddle">
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="src">
<xsl:eval>this.firstChild == null ? "nothing.gif" :
this.getAttribute("open") == "Y" ? "minus.gif" : "plus.gif"
</xsl:eval>
</xsl:attribute>
</img>
<img align="absmiddle">
<xsl:attribute name="src"><xsl:value-of select="@icon"/></xsl:attribute>
</img>
<xsl:value-of select="@title"/>
<BR/>
<xsl:apply-templates match="node"/>
</xsl:template>
</xsl:stylesheet>
Have fun...
____________________________________________________________________________
Steve | Consulting PM & XML Technology Evangelist | smuench@xxxxxxxxxx
Muench | Java Business Objects Dev Team | geocities.com/~smuench
Get to know JBO at http://javatools/jbo/owa/walkthrough
Do you XML? http://xml.us.oracle.com
--- Begin Message ---
|
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








