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

Re: rendering a treeview *hairy problem*

Subject: Re: rendering a treeview *hairy problem*
From: "Mattias Konradsson" <preacher@xxxxxxxxxxx>
Date: Thu, 1 Feb 2001 16:19:16 +0100
thread.gif
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) &gt; 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>&#160;<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


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.