[xsl] rendering a treeview *hairy problem*

Subject: [xsl] rendering a treeview *hairy problem*
From: "Mattias Konradsson" <preacher@xxxxxxxxxxx>
Date: Thu, 1 Feb 2001 06:48:28 +0100
weee, this problem has been on my mind the last couple of days... So roll up
your sleeves and get your gray ones going, hopefully they work better than
mine :)

I have an forum with xml structure something like this


    <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  postID="5" Subject="Second Post"/>

and I want to make an xslt stylesheet that outputs a graphical hierarchial
tree based on this, this is what I got sofar

 <xsl:template match="/">

 <xsl:template match="forum">
           <xsl:for-each select="thread">
                <xsl:apply-templates />

 <xsl:template match="post">
   <div style="padding-left:12px">
             <xsl:when test="position() = last()">
               <img align="middle" src="/community/images/thread.gif"
alt="" border="0"/>
     <xsl:otherwise >
       <img align="middle" src="/community/images/branch.gif"  alt=""

   <xsl:value-of select="@subject" /> &#160; <xsl:value-of
select="@nickname" />

   <xsl:if test="position() = last()">last</xsl:if>
   <xsl:value-of  select="count(child::post)"/>

           <xsl:apply-templates />

branch.gif is a a image where the the tree branches but has more nodes after
it and thread.gif is a L-shaped image for the last node in a branch . This
is what's produced (here we go with the ascii)

I- First Post
    L Reply to First Post
    L  Second Reply to First Post
        L First Reply to Second Reply to first post
L  Second Post

Sofar so good, the padding takes care of the indenting and we check to see
if a node is last to select image. The *problem is that there should be
Lines connecting the First and Second Post and any Siblings (if there were
any) So I want it to look like this:

I- First Post
I   L Reply to First Post
I   L Second Reply to First Post
I   I     L First Reply to Second Reply to first post
I   L  Third Reply to first post
L  Second Post

But I haven't been able to figure out a good solution.. the current solution
is recursive but for this to work you'd have to keep track on which siblings
line graphics should be before replies. Anyway, I hope I've explained it
well, if anyone can solve this hairy problem I'd be forever grateful :)

Best Regards
Mattias Konradsson

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

Current Thread