XSLT and XPath function reference in alphabetical order
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 5, translated from German)
Context information within a sequence
Return value: A (positive) integer of xs:integer type; the position of the current item in a sequence, the context sequence. If the context sequence is empty, the function returns the empty sequence.
Purpose of use:
The fn:position() function outputs in the form of a positive xs:integer integer the position (index number) of the currently processed item of the current sequence (dynamic context). Its main fields of application are the output of the current position and the query of the current position in the context of predicate tests.
The function returns a xs:integer integer which corresponds to the position of the context item in the context size of the currently processed sequence. If the context item is not defined, a runtime error is reported in the dynamic context (err:XPDY0002).
Notice: In XPath 1.0, the function refers to the context in the currently processed node set.
Example – test for a predefined position in a sequence:
<xsl:if test="fn:position() = 3"> <hr/> </xsl:if>
In this example, during the processing of an element which is at the third position in a node sequence, a horizontal rule <hr/> is inserted.
fn:position() 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