Returns the line number of a selected node within the XML document (or external entity) that contains it.
line-number() ➔ xs:integer
There are no arguments
line-number($node as node()) ➔ xs:integer
The node whose line number is required
Requires Saxon-PE or Saxon-EE.
Notes on the Saxon implementation
Available since Saxon 8.1.
This function returns the line number of a selected node within the XML document (or external entity) that contains it. If the argument is supplied, it must be a node; if the argument is omitted, the context item is used, in which case the context item must be a node. If line numbers are not maintained for the current document, the function returns -1.
To ensure that line numbers are maintained, use the
-l (letter ell) option
on the command line.
Note that the value returned is dependent on information supplied by the XML parser. For an element node, SAX parsers generally report the line and column position of the ">" character at the end of the start tag. StAX parsers by contrast report the position of the "<" character at the start of the start tag. SAX parsers report line and column numbers only for element nodes, so for any other kind of node, the returned value will be -1.
From release 9.0, the
-l option also causes line numbers to be copied from
a source document to a result document when the xsl:copy-of instruction is applied to a document or
element node. For elements created using other instructions, the line number will
reflect the position of the instruction in the stylesheet or query that caused the
element to be created.