This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: rendering a treeview *hairy problem*
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: Re: [xsl] rendering a treeview *hairy problem*
- From: "Mattias Konradsson" <preacher at fragzone dot se>
- Date: Thu, 1 Feb 2001 16:19:16 +0100
- References: <7DFB47C9CEBDD411A38300D0B77F3306084670@strauss.proxima-tech.com.au> <007901c08c12$9afbb120$01010a0a@BORG1>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Well, it sure was bloody, frustrating and hairtearing but atleast I
learned a lot :) Here's the final mega-recursion-braintwister stylesheet,
read at your own peril. At least it makes a good exercise :)
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="forum">
<table border="0" cellspacing="0" cellpadding="0">
<xsl:for-each select="thread">
<xsl:apply-templates />
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="post">
<tr valign="bottom" height="12">
<td>
<xsl:if test="not (parent::thread)">
<xsl:for-each select="ancestor::thread ">
<xsl:choose>
<xsl:when test="following-sibling::thread">
<img align="top" src="/community/images/straight.gif" alt=""
border="0" hspace="0" vspace="0" width="12" height="14"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:if>
<xsl:for-each select="ancestor::thread | ancestor::post ">
<xsl:choose>
<xsl:when test="following-sibling::thread or
following-sibling::post">
<xsl:choose>
<xsl:when test="parent::post or parent::thread">
<img align="top" src="/community/images/straight.gif" alt=""
border="0" hspace="0" vspace="0" width="12" height="14"/>
</xsl:when>
<xsl:otherwise>
<xsl:if test="not(following-sibling::thread)">
<img align="top" src="/community/images/blank.gif" alt=""
border="0" hspace="0" vspace="0" width="12" height="14"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:if test="not(parent::forum)">
<xsl:if test="not(parent::thread/following-sibling::thread)">
<img align="top" src="/community/images/blank.gif" alt=""
border="0" hspace="0" vspace="0" width="12" height="14"/>
</xsl:if>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:choose>
<xsl:when test="count(ancestor::*) != 2">
<xsl:choose>
<xsl:when test="position() = last()">
<img align="top" src="/community/images/thread.gif" alt=""
border="0" hspace="0" vspace="0" width="12" height="14"/>
</xsl:when>
<xsl:otherwise >
<img align="top" src="/community/images/branch.gif" alt=""
border="0" hspace="0" vspace="0" width="12" height="14"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="not(parent::thread/following-sibling::thread)">
<img align="top" src="/community/images/thread.gif" alt=""
border="0" hspace="0" vspace="0" width="12" height="14"/>
</xsl:when>
<xsl:otherwise>
<img align="top" src="/community/images/branch.gif" alt="" border="0"
hspace="0" vspace="0" width="12" height="14"/> </xsl:otherwise>
</xsl:choose>
<xsl:if test="count(child::post) = 0">
<img align="top" src="/community/images/endnode.gif" alt="" border="0"
hspace="0" vspace="0" width="12" height="14"/>
</xsl:if>
<xsl:if test="count(child::post) > 0">
<img align="top" src="/community/images/parentnode.gif" alt=""
border="0" hspace="0" vspace="0" width="12" height="14"/>
</xsl:if>
<a href="#"><xsl:value-of select="@subject" /></a> <xsl:value-of
select="@nickname" />
<xsl:apply-templates />
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
>
> <forum>
>
> <thread>
> <post postID="1" Subject="First Post">
> <post postID="2" Subject="Reply to first Post"/>
> <post postID="3" Subject="Second Reply to first Post">
> <post postID="4" Subject="First Reply to Second Reply to
first
> Post"/>
> </post>
> </post>
> <post postID="5" Subject="Second Post"/>
> </thread>
> <thread>
> ...
> </thread>
> </forum>
>
> and I want to make an xslt stylesheet that outputs a graphical hierarchial
> tree based on this, this is what I got sofar
mvh
---
Mattias Konradsson
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list