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

Nodes, strings, branches

Subject: Nodes, strings, branches
From: lachance@xxxxxxxxxxxxxxxxx (Francois Lachance)
Date: Sat, 8 Apr 2000 10:47:07 -0400 (EDT)
nodes and branches
 
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


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.