Subject: RE: problem using last() within <xsl:for-each-group>
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 1 Apr 2005 12:28:18 +0100
|
I've just tried this. There's incorrect output for last() in Saxon 8.1, but
it's fine in later releases (8.2 and 8.3).
The reason current() doesn't output anything is that the string-value of all
your element nodes is a zero-length string.
I've taken the liberty of adding this to my test collection - please be
aware that anything sent to this list may turn up in all sorts of places in
the future!
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Matt Heckel [mailto:matt_heckel@xxxxxxxxx]
> Sent: 01 April 2005 11:26
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: problem using last() within <xsl:for-each-group>
>
> Once again, my intuition has failed me and I need
> help. I was trying to find the last item within the
> last group of a data population and I've run into some
> interesting (ie. frustrating) behavior. For the
> record, I'm using SAXON8b to process an XSLT V. 2.0
> stylesheet.
>
> As I mentioned, I'm grouping using for-each-group and
> then iterating through each group using for-each on
> the current-group(). While using for-each through the
> current-group()using everything seems to be working
> just fine. That is, the position() value is sequential
> and last() returns the total iterations for the
> current-group(). However, in the outer
> for-each-group(ing) the last() function doesn't seem
> to be returning the right value. Since both for-each
> and for-each-group change the context when invoked, it
> seems they should both behave the same way? Also, I
> was playing with the current() function and it doesn't
> seem to evaluate at all. This is of lesser importance
> to me for this particular problem I'm facing but
> thought I would ask for future reference. Thanks VERY
> much. My source doc and stylesheet are as follows.
>
> <CASTDataset>
> <ETL_AIR_7 ACFT_TYP_SYN_NM="E-2"
> CARRIER_NM="Constellation"/>
> <ETL_AIR_7 ACFT_TYP_SYN_NM="EA-18G"
> CARRIER_NM="Constellation"/>
> <ETL_AIR_7 ACFT_TYP_SYN_NM="F-18C"
> CARRIER_NM="Constellation"/>
> <ETL_AIR_7 ACFT_TYP_SYN_NM="F-18E"
> CARRIER_NM="Constellation"/>
> <ETL_AIR_7 ACFT_TYP_SYN_NM="E-2"
> CARRIER_NM="Eisenhower"/>
> <ETL_AIR_7 ACFT_TYP_SYN_NM="EA-18G"
> CARRIER_NM="Eisenhower"/>
> <ETL_AIR_7 ACFT_TYP_SYN_NM="F-18C"
> CARRIER_NM="Eisenhower"/>
> <ETL_AIR_7 ACFT_TYP_SYN_NM="F-18E"
> CARRIER_NM="Eisenhower"/>
> <ETL_AIR_7 ACFT_TYP_SYN_NM="E-2"
> CARRIER_NM="Enterprise"/>
> <ETL_AIR_7 ACFT_TYP_SYN_NM="EA-18G"
> CARRIER_NM="Enterprise"/>
> <ETL_AIR_7 ACFT_TYP_SYN_NM="F-18C"
> CARRIER_NM="Enterprise"/>
> <ETL_AIR_7 ACFT_TYP_SYN_NM="F-18E"
> CARRIER_NM="Enterprise"/>
> </CASTDataset>
>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:fn="http://www.w3.org/2004/10/xpath-functions"
> xmlns:xdt="http://www.w3.org/2004/10/xpath-datatypes">
>
> <xsl:output method="text" version="1.0"
> encoding="UTF-8" indent="yes"
> omit-xml-declaration="yes"/>
>
> <xsl:variable name="endline" select="'
x;'"/>
> <xsl:template match="/">
> <xsl:for-each-group select="CASTDataset/ETL_AIR_7"
> group-by="@CARRIER_NM">
> <xsl:value-of select="concat('The current node is ',
> current())"/>
> <xsl:value-of select="$endline"/>
> <xsl:value-of
> select="concat(' For the ', @CARRIER_NM, ' group, the
> current position is ', position(), ' and last is ',
> last())"/>
> <xsl:value-of select="$endline"/>
> <xsl:for-each select="current-group()">
> <xsl:value-of select="concat('For the items within the
> current-group(), ACFT_TYP_SYN_NM is ',
> @ACFT_TYP_SYN_NM, ',the current position is ',
> position(), ' and last is ', last())"/>
> <xsl:value-of select="$endline"/>
> </xsl:for-each>
> </xsl:for-each-group>
> </xsl:template>
> </xsl:stylesheet>
>
>
>
>
>
> __________________________________
> Yahoo! Messenger
> Show us what our next emoticon should look like. Join the fun.
> http://www.advision.webevents.yahoo.com/emoticontest
|