This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Nodes, strings & 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]"/>

<!-- 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>The <w function="item" group="secondary" n="list2">green</w> taxi slid
to a $
<l>The <w function="item" group="primary" n="list1">red</w> truck halted
briefl$
<l><w>The</w> <w function="item" group="secondary" n="list2">purple</w>
van spe$
</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>The <w function="item" group="secondary" n="list2">green</w> taxi slid
to a $
<l>The <w function="item" group="primary" n="list1">red</w> truck halted
briefl$
<l><w>The</w> <w function="item" group="secondary" n="list2">purple</w>
van spe$
</lg>
<lg>
<w function="item" n="list5">goose</w>
</lg>
</doc>

******
Thanks for all the help on this.


-- 
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]