xsl-list
[Top] [All Lists]

Re: xsl-list Digest 22 Jun 2005 05:10:01 -0000 Issue 455

2005-06-22 13:26:15

On Jun 22, 2005, at 1:10 AM, xsl-list-digest- help(_at_)lists(_dot_)mulberrytech(_dot_)com wrote:

Date: Tue, 21 Jun 2005 23:24:29 +0100
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
From: David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk>
Subject: Re: [xsl] Contexts that are atomic values
Message-Id: 
<200506212224(_dot_)XAA23479(_at_)penguin(_dot_)nag(_dot_)co(_dot_)uk>


Is this behavior normal?


Yes, or at least it will be. (It's best to say if you are using xslt2:-)

distinct-values() as its name suggests returns values not teh nodes the
values they were in, so it's like going

<xsl:for-each select="(1,2,3,4)"

in which the current item would be the integers 1 2 3 4 but being
integers rather than nodes they can't be used as the base for any
relative XPath (or even / as that depends on the current dpcument)

That there's no current node while processing a scalar value, I understand, but why can't there be a current document?


you can go
<xsl:variable name="input" select="/"/>
as a top level variable (or anywhere outside the for-each)
and then use

                 <xsl:apply-templates
                 select="$input/key('by-type',current())"/>
or equivalently

                 <xsl:apply-templates
                 select="key('by-type',current(),$input)"/>

Or perhaps more naturally don't use distinct-values at all, but ciew it
as a grouping problem

<xsl:for-each-group select="item" group-by="@type">
...

for-each-group groups the nodes themselves rather than just the values.

I don't know why I didn't think of using a variable. As for 'for- each-group', I didn't know it existed at all :-) Of, course, the for- each-group approach is the best solution (once you figure out there's also a current-group() function, which is not obvious from the w3.org documentation...).

Thanks a lot for your help,

MC
--
2p3p[dl!d2+s!%0=(_at_)l!l^!<#]s#[s/0ds^]s(_at_)[p]s&[ddvs^3s!l#x0<&2+l.x]ds.x


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



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