recursion and looping

Subject: recursion and looping
From: lachance@xxxxxxxxxxxxxxxxx (Francois Lachance)
Date: Thu, 23 Mar 2000 12:08:15 -0500 (EST)
AIM - group elements according to attribute  value [indeterminate number
of values
Strategy - apply tempates subsequent subsets of nodeset
Problem - how to build the recursion without infinte  loop

Question: is the looping induced by the following stylesheet casued by a
failure to shift context node? If so how can one pass a param value that
cause a shift in context node? Or is this totally wrong-tree barking?

XSLT file

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:output method="html"/>

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


<xsl:template match="lg">
<xsl:call-template name="grouper" select="//w[@function='item']">
<xsl:with-param name="listname" select="'list1'"/>
</xsl:call-template>
</xsl:template>


<xsl:template name="grouper">

<xsl:param name="listname"/>

<xsl:param name="nodeset" select="//w[@n=$listname]"/>
<xsl:param name="nextset" select="//w[@n!=$listname]a"/>

<xsl:param name="nextlistname" select="$nextset/@n"/>

<xsl:if test="not($nextset='')"> 

<xsl:for-each select="$nodeset">
<xsl:sort select="." order="descending"/>
<xsl:value-of select="."/>
</xsl:for-each>

<xsl:call-template name="grouper">
<xsl:with-param name="listname" select="$nextlistname"/>
</xsl:call-template>

</xsl:if>

</xsl:template>

</xsl:stylesheet>


XML file

<lg>
<l>The <w function="item" n="list1" group="primary">yellow</w> cab drove
away.</l>
<l>The <w function="item" n="list2" group="secondary">green</w> bus slides
to a stop.</l>
<l>The <w function="item" n="list1" group="primary">red</w> truck halted
briefly.<w>nonce</w></l>
<l>The <w function="item" n="list2" group="secondary">purple</w> van sped
away.</l>
</lg>



Desired output: lists of items

yellow red
purple green 

Thanks


-- 
Francois Lachance
Post-doctoral Fellow
projet HYPERLISTES project
http://www.humanities.mcmaster.ca/~hyplist/


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


Current Thread