xsl-list
[Top] [All Lists]

Re: AW: XPATH restricting preceding nodes

2003-09-10 06:39:51
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"?>
<top>
        <page>
                <entry text='aaa'/>
                <entry text='bbb'/>
                <entry text='aaa'/>
        </page>
        <page>
                <entry text='ccc'/>
                <entry text='bbb'/>
                <entry text='ccc'/>
        </page>
</top>

T:\ftemp>type erwin.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

<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[(_at_)text=current()/@text])">
      Entry: <xsl:value-of select="@text"/>
    </xsl:if>
  </xsl:for-each>
 </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>saxon erwin.xml erwin.xsl

    Page 1:

      Entry: aaa
      Entry: bbb
    Page 2:

      Entry: ccc
      Entry: bbb
T:\ftemp>


--
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(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
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:     http://XMLGuild.info
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc


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



<Prev in Thread] Current Thread [Next in Thread>