|
Subject: RE: [xsl] selecting from sequences From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Thu, 18 Dec 2008 15:44:55 -0000 |
> If for example $seq contains elements a, b, c, b, e:
>
> how do I select
> A - everything before the first b
> B - everything from the first b to the end
> C - the position of the first b?
>
You don't actually say whether this is 1.0 or 2.0, but since you're talking
sequences rather than node-sets, I assume 2.0. The following might not be
the best solution, but works:
<xsl:variable name="index" as="xs:integer*">
<xsl:for-each select="$seq">
<xsl:if test="self::b">
<xsl:sequence select="position()"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
then
A - $seq[position() lt $index[1]]
B - $seq[position() ge $index[1]]
C - $index[1]
The details of course depend on what you want to happen if there is no b
element in the sequence.
Alternatively
<xsl:for-each-group select="$seq" group-starting-with="b">
might do what you want - but it depends exactly what you want to do.
Michael Kay
http://www.saxonica.com/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] selecting from sequences, Michael Kay | Thread | Re: [xsl] selecting from sequences, Andrew Welch |
| Re: [xsl] selecting from sequences, David Carlisle | Date | Re: [xsl] selecting from sequences, Ruud Grosmann |
| Month |