XML technologies / XSLT / XSLT and XPath functions / Alphabetical XSLT and XPath reference / position

(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:position

Category:

Context information within a sequence

Origin:

XPath 1.0

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.

Call/Arguments:

fn:position()

No arguments.

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.

Function definition:

XPath 1.0:

position()=> number

XPath 2.0:

fn:position() as xs:integer?

   

 

 

 

back to top