fn:trace

Returns the value of the first argument after outputting a diagnostic message.

trace($value as item()*) ➔ item()*

Arguments

 

$value

item()*

The value to be traced, and to be returned as the function result

Result

item()*

trace($value as item()*, $label as xs:string) ➔ item()*

Arguments

 

$value

item()*

The value to be traced, and to be returned as the function result

 

$label

xs:string

Label to be included in the trace output

Result

item()*

Namespace

http://www.w3.org/2005/xpath-functions

Links to W3C specifications

XPath 3.1 Functions and Operators

Notes on the Saxon implementation

Saxon by default outputs trace messages to System.err. However, the output may be redirected to a TraceListener or to an alternative output destination.

The Saxon implementation outputs the value of each item in a sequence as it is evaluated (except when the sequence is empty, in which case it outputs "empty sequence" at the start). Atomic values are output by converting them to a string, nodes by calling getPath() to generate a path expression to the node. With complex expressions the order of evaluation may be rather different from the expected order.

The trace output is directed to System.err, this may be redirected by using 2>log.txt on the command line. If a TraceListener has been nominated, then instead of writing the output to System.err, the information instead results in events being notified to the TraceListener.

The single-argument form of this function specified in XPath 3.1 is available since Saxon 9.7.