xsl-list
[Top] [All Lists]

RE: [xsl] selecting from sequences

2008-12-18 10:45:29
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/


--~------------------------------------------------------------------
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>
--~--