Re: AW: [xsl] XPATH restricting preceding nodes

Subject: Re: AW: [xsl] XPATH restricting preceding nodes
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 10 Sep 2003 09:39:51 -0400
At 2003-09-10 14:45 +0200, Kloeck, Erwin wrote:
your solution works. This was what I needed. Now I have to read a little about what xls:key does to also understand this. :-)

Actually, when doing subgrouping on a tree you don't *always* have to use keys.

When I teach grouping in XSLT 1.0 I go through three different methods: by axes, by variables and by keys. I find that multi-level grouping or subgrouping can be a lot easier by variables when you don't need to act on node sets.

But I also go over keys as a standalone concept, not just in grouping ... a week from Monday we have a public European delivery of our courses that you might be interested in where we go over every element, attribute and function of both XSLT and XPath, and in a separate course that week, every formatting object of XSL-FO.

I hope the example below helps.

.................... Ken

T:\ftemp>type erwin.xml
<?xml version="1.0" encoding="iso-8859-1"?>
                <entry text='aaa'/>
                <entry text='bbb'/>
                <entry text='aaa'/>
                <entry text='ccc'/>
                <entry text='bbb'/>
                <entry text='ccc'/>

T:\ftemp>type erwin.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="";

<xsl:output method="text"/>

<xsl:template match="top">
<xsl:for-each select="page">
Page <xsl:value-of select="position()"/>:
<xsl:variable name="entries" select="entry"/>
<xsl:for-each select="$entries">
<xsl:if test="generate-id(.)=generate-id($entries[@text=current()/@text])">
Entry: <xsl:value-of select="@text"/>

T:\ftemp>saxon erwin.xml erwin.xsl

Page 1:

      Entry: aaa
      Entry: bbb
    Page 2:

      Entry: ccc
      Entry: bbb

-- Next public European delivery: 3-day XSLT/2-day XSL-FO 2003-09-22 Next public US delivery: 3-day XSLT/2-day XSL-FO 2003-10-13 Instructor-led on-site corporate, government & user group training for XSLT and XSL-FO world-wide: please contact us for the details

G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                       Definitive XSLT and XPath
ISBN 0-13-140374-5                               Definitive XSL-FO
ISBN 1-894049-08-X   Practical Transformation Using XSLT and XPath
ISBN 1-894049-11-X               Practical Formatting Using XSL-FO
Member of the XML Guild of Practitioners:
Male Breast Cancer Awareness

XSL-List info and archive:

Current Thread