This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Nodes, strings, branches
- To: XSL-List at mulberrytech dot com
- Subject: Nodes, strings, branches
- From: lachance at chass dot utoronto dot ca (Francois Lachance)
- Date: Sat, 8 Apr 2000 10:47:07 -0400 (EDT)
- Reply-To: xsl-list at mulberrytech dot com
As promised I have reworked a stylesheet to group elements based on
attribute values.
<?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:call-template name="grouper">
<xsl:with-param name="nodes" select="//w[@function='item']"/>
<xsl:with-param name="listname" select="string(//w/@n)"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="grouper">
<xsl:param name="nodes"/>
<xsl:param name="listname"/>
<xsl:param name="nodeset" select="$nodes/self::w[@n=$listname]"/>
<xsl:param name="nextset" select="$nodes/self::w[@n!=$listname]"/>
<!--
The following part was developed thanks to Craig Squires who remind
me to be mindful of datatypes or objects
-->
<!--
the following function binds a variable to the first occurence
of an attribute node in a nodeset
-->
<xsl:param name="tempholder"select="$nextset/@n"/>
<!--
the following function binds a variable to a string
-->
<xsl:param name="nextlistname" select="string($tempholder)"/>
<!--
Phil Lanch helped me figure out the very important difference between
testing on a string and testing on a node. Again the reminder re datatypes
or objects
-->
<xsl:if test="$nodes">
<xsl:for-each select="$nodeset">
<xsl:sort select="." order="descending"/>
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:text> /\/\/\ </xsl:text>
<xsl:call-template name="grouper">
<xsl:with-param name="nodes" select="$nextset"/>
<xsl:with-param name="listname" select="$nextlistname"/>
</xsl:call-template>
<!--
*smile* try passing $tempholder instead of $nextlistname
in the recursive call-template
and compare the results on the two data sets.
Any one venture an explanation?
-->
</xsl:if>
</xsl:template>
</xsl:stylesheet>
************
First data set: no branching in the parent's parent node
<lg>
<l>The <w function="item" group="primary" n="list1">yellow</w> cab drove away.</l>
<l>The <w function="item" group="secondary" n="list2">green</w> taxi slid to a stop.</l>
<l>The <w function="item" group="primary" n="list1">red</w> truck halted briefly.<w>nonce</w></l>
<l><w>The</w> <w function="item" group="secondary" n="list2">purple</w> van sped away.</l>
</lg>
Second data set: branching in the parent's parent node
<doc>
<lg>
<l>The <w function="item" group="primary" n="list1">yellow</w> cab drove away.</l>
<l>The <w function="item" group="secondary" n="list2">green</w> taxi slid to a stop.</l>
<l>The <w function="item" group="primary" n="list1">red</w> truck halted briefly.<w>nonce</w></l>
<l><w>The</w> <w function="item" group="secondary" n="list2">purple</w> van sped away.</l>
</lg>
<lg>
<w function="item" n="list5">goose</w>
</lg>
</doc>
***
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