XPath and XQuery Specification Information

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  User Guide and Reference > Interface and Environment > The Graphical User Interface (GUI) > Output Window: XPath/XQuery >

XPath and XQuery Specification Information

XPath 1.0 expressions


XPath 1.0 functions must be entered without any namespace prefix.
The four node tests by type are supported: node(), text(), comment(), and processing-instruction().


XPath 2.0 and 3.1 expressions


String (e.g. 'Hello') and numeric literals (e.g. 256) are supported. To create other literals based on XML Schema types, you use a namespace-prefixed constructor (e.g. xs:date('2004-09-02')). The namespace prefix that you use for XML Schema types must be bound to the XML Schema namespace: http://www.w3.org/2001/XMLSchema, and this namespace must be declared in your XML file.
XPath 2.0 and 3.1 functions used by the XPath Evaluator belong to the namespace http://www.w3.org/2005/xpath-functions. Conventionally, the prefix fn: is bound to this namespace. However, since this namespace is the default functions namespace used by the XPath Evaluator, you do not need to specify a prefix on functions. If you do use a prefix, make sure that the prefix is bound to the XPath Functions namespace, which you must declare in the XML document. Examples of function usage: current-date() (with Functions namespace not declared in XML document); fn:current-date() (with Functions namespace not declared in XML document, or declared in XML document and bound to prefix fn:). You can omit the namespace prefix even if the Functions namespace has been declared in the XML document with or without a prefix; this is because a function so used in an XPath expression is in the default namespace—which is the default namespace for functions.
Altova's XPath extensions are in the namespace http://www.altova.com/xslt-extensions.


Note:To summarize the namespace issue: If you use constructors or types from the XML Schema namespace, you must declare the XML Schema namespace in the XML document and use the correct namespace prefixes in the XPath expression. You do not need to use a prefix for XPath functions.


Datatypes in XPath 2.0 and 3.1

If you are evaluating an XPath 2.0 or 3.1 expression for an XML document that references an XML Schema and is valid according to this schema, you must explicitly construct or cast datatypes that are not implicitly converted to the required datatype by an operation. In the XPath 2.0 and 3.1 Data Models used by the built-in XPath engine, all atomized node values from the XML document are assigned the xs:untypedAtomic datatype. The xs:untypedAtomic type works well with implicit type conversions. For example, the expression xs:untypedAtomic("1") + 1 results in a value of 2 because the xs:untypedAtomic value is implicitly promoted to xs:double by the addition operator. Arithmetic operators implicitly promote operands to xs:double. Comparison operators promote operands to xs:string before comparing.


In some cases, however, it is necessary to explicitly convert to the required datatype. For example, if you have two elements, startDate and endDate, that are defined as being of type xs:date in the XML Schema, then, for example, using the XPath 2.0 expression endDate - startDate will show an error. On the other hand, if you use xs:date(endDate) - xs:date(startDate) or (endDate cast as xs:date) - (startDate cast as xs:date), the expression will correctly evaluate to a singleton sequence of type xs:dayTimeDuration.


Note:The XPath Engines used by the XPath Evaluator are also used by the Altova XSLT Engine, so XPath 2.0 or 3.1 expressions in XSLT stylesheets that are not implicitly converted to the required datatype must be explicitly constructed as or cast to the required datatype.


String length of character and entity references

When character and entity references are used as the input string for the string-length() function, the references cannot be resolved, and the length of the unresolved text string is returned. Within an XSLT environment, however, these references would have meaning, and the length of the resolved string is returned.


XPath 2.0 and 3.1 Functions Support

See the appendices.


© 2019 Altova GmbH