[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

rendering a treeview *hairy problem*

Subject: rendering a treeview *hairy problem*
From: "Mattias Konradsson" <preacher@xxxxxxxxxxx>
Date: Thu, 1 Feb 2001 06:48:28 +0100
treeview image problem
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

<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

 <xsl:template match="/">
     <xsl:apply-templates/>
 </xsl:template>

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


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


   <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 />
       </div>
 </xsl:template>

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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.