XSLT and XPath function reference in alphabetical order
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 5, translated from German)
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
fn:index-of
Category:
Functions for sequences
Origin:
XPath 2.0
Return value:
A sequence of one or several xs:integer integers; the index number(s) counted upwards from 1 describing the position(s) of the values searched for in the input sequence.
Call/Arguments:
fn:index-of($inputSequence?, $comparativeValue, $collation-URI?)
$inputSequence:
A sequence of one or several atomic items of xs:anyAtomicType type. If there are items of non-atomic type (e.g. nodes or token lists) in the input sequence, the relevant items are atomised in advance.
$comparativeValue:
Obligatory. An atomic value of xs:anyAtomicType type whose occurence and position shall be tested in the input sequence.
$collation-URI:
Optional. The third argument consists of a xs:string string which names the URI string of the applicable collation, where appropriate, for string comparisons. The value has to lexically correspond to the xs:anyURI type. If this is not the case, an error message (»Invalid collationURI«) is outputted.
Purpose of use:
The function tests an input sequence for the existence of a comparative value also passed on. The items of the input sequence as well as the comparative value have to be atomic values. If there are, for example, nodes in the input sequence, their value is atomised in advance (see example 4).
The comparison between an item of the input sequence and the comparative value is made according to the rules of the eq operator. For the comparison of string values, the default collation (if any) is used or the collation which is identified by the URI which can be passed on as third argument. If no third argument is passed on, the default collation is used for the comparison. If the tested sequence does not consist of strings but a $collation-URI argument has been passed on, it will be ignored.
If the types of the sequence and the comparative value are contradictory and therefore their equality cannot be determined according to the eq operator, they are considered as being different. Attention: In previous versions of XPath 2.0 an error was reported instead!
In case the equality of an item of the sequence with the comparative value is determined, the index number of the relevant item is added to the result sequence. The index numbers start with 1 for the first item of the sequence. Since the index numbers of all found matches are added in the same order, always a sequence in ascending order is generated.
If no match can be found or the input sequence is empty, an empty result sequence is returned.
Example 1 - searched value contained in input sequence:
fn:index-of((15, 25, 35, 45), 35)
returns (3).
Example 2 - searched value not contained in input sequence:
fn:index-of((15, 25, 35, 45), 40)
returns the empty sequence ().
Example 3 - searched value contained in input sequence multiple times:
fn:index-of((15, 25, 35, 35, 25, 15), 25)
returns the sequence (2, 5).
Example 4 - application on xs:NMTOKEN token list values:
If the @colours attribute has the value »red green blue« and it is of xs:NMTOKEN type, the following applies:
fn:index-of(@colours, "blue")
returns (3).
The @colours attribute is a token list. The xs:NMTOKEN type is considered as non-atomic, which means the value of the attribute is accordingly atomised and split up into a sequence of three strings.
Function definition:
XPath 1.0:
The function is not available.
XPath 2.0:
fn:index-of($seqParam as xs:anyAtomicType*,
$srchParam as xs:anyAtomicType) as xs:integer*
fn:index-of($seqParam as xs:anyAtomicType*,
$srchParam as xs:anyAtomicType,
$collation as xs:string) as xs:integer*
<< back | next >> |
Copyright © Galileo Press, Bonn 2008
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSLT 2.0 & XPath 2.0" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn, Germany