[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: rendering a treeview *hairy problem*
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
|
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
|