|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: rendering a treeview *hairy problem*
Mattias Konradsson <preacher@xxxxxxxxxxx> wrote:
> 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 :)
I think you can achieve the same effect by mere invocation of templates with
parameters - without using neither ancestor axis nor <xsl:choose>. Please find a
suggestion below. I have outlined the images by preformatted pieces of text. All
variables and parameters there are RTFs, processed by xsl:copy-of; therefore, it
is safe to put an <img/> element into $blank, $straight, etc...
Hope you enjoy it,
Regards,
Nikolai
=============================================
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<!-- ============================ -->
<!-- Single pieces of tree view -->
<xsl:variable name="blank">
<xsl:text> </xsl:text>
</xsl:variable>
<xsl:variable name="straight">
<xsl:text>| </xsl:text>
</xsl:variable>
<xsl:variable name="branch">
<xsl:text>|--</xsl:text>
</xsl:variable>
<xsl:variable name="endnode">
<xsl:text>'--</xsl:text>
</xsl:variable>
<xsl:variable name="parentnode">
<xsl:text>+ </xsl:text>
</xsl:variable>
<!-- ============================ -->
<!-- Basics -->
<xsl:template match="forum">
<table width="100%">
<xsl:apply-templates select="thread"/>
</table>
</xsl:template>
<xsl:template match="thread">
<tr>
<td>
<table width="100%">
<xsl:apply-templates select="post"/>
</table>
</td>
</tr>
</xsl:template>
<!-- ======================================================= -->
<!-- Templates to dispatch selection of tree building blocks -->
<!-- Note that there is no HTML inside - only the logic -->
<!-- Single post that is not a last reply -->
<xsl:template match="post[following-sibling::post]">
<xsl:param name="prefix"/>
<xsl:call-template name="draw-post">
<xsl:with-param name="current-prefix">
<xsl:copy-of select="$prefix"/>
<xsl:copy-of select="$branch"/>
</xsl:with-param>
<xsl:with-param name="children-prefix">
<xsl:copy-of select="$prefix"/>
<xsl:copy-of select="$straight"/>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<!-- Single post that is a last reply -->
<xsl:template match="post" priority="-1">
<xsl:param name="prefix"/>
<xsl:call-template name="draw-post">
<xsl:with-param name="current-prefix">
<xsl:copy-of select="$prefix"/>
<xsl:copy-of select="$endnode"/>
</xsl:with-param>
<xsl:with-param name="children-prefix">
<xsl:copy-of select="$prefix"/>
<xsl:copy-of select="$blank"/>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<!-- ========================== -->
<!-- Actually draw a post entry -->
<!-- The current node must be "post". -->
<xsl:template name="draw-post">
<xsl:param name="current-prefix"/>
<xsl:param name="children-prefix"/>
<tr>
<td>
<pre>
<xsl:copy-of select="$current-prefix"/>
<xsl:if test="post">
<xsl:copy-of select="$parentnode"/>
</xsl:if>
<xsl:value-of select="@Subject"/>
</pre>
</td>
</tr>
<xsl:apply-templates select="post">
<xsl:with-param name="prefix" select="$children-prefix"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
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
|

Cart








