6. XPath escapes

The language used to write formulas is very close to the one used by other spreadsheet software. The rationale is of course to make it easy to learn. But in fact, formulas are internally translated to another, less known language: XPath 1.0. XPath can be considered as the standard, native, expression language of XML.

This design allows to freely mix XPath expressions with ``ordinary'' expressions. This is what we call XPath escapes.

The syntax of XPath escapes is simply: `XPath_expression`. (The character used here is the backquote '`'.)

Inside XPath_expression, the backquote character '`' must be escaped by doubling it. Example: `concat("XXE ", " is ````challenging to learn''.")`.

An XPath expression can reference the local variables of the formula using the usual XPath syntax for that: $variable_name.

Using XPath escapes is often mandatory. Example 1: add 2 to the value of attribute count of the element containing the formula:

= `@count` + 1

Example 2 taken from the tutorial: get element with ID B2&"_desc" found in external document "products.html" (pathname relative to the file containing the document being edited).

location = (("products.html#" & trim(B2)) & "_desc")
=`document($location, .)`

This XPath-based design also allows to use XPath functions as if they were regular spreadsheet functions. In order to do this, simply add an underscore '_' at the beginning of the XPath function name and, if this name contains dashes '-', replace them by underscores. Examples: