oxy_xpath() Function

This function is used to evaluate XPath expressions.

The oxy_xpath() function has the following signature:

  • oxy_xpath( XPathExpression [,processChangeMarkers,value][,evaluate,value])

    It evaluates the given XPath 2.0 expression using Saxon 9 and returns the result. XPath expressions that depend on the cursor location can be successfully evaluated only when the cursor is located in the actual XML content. Evaluation fails when the current editing context is inside a referenced xi:include section or inside artificially referenced content (for example, DITA conref or topicref references).

    The parameters of the function are as follows:

    • A required expression parameter, which is the XPath expression to be evaluated.
    • An optional processChangeMarkers parameter, followed by its value, which can be either true or false (default value). When you set the parameter to true, the function returns the resulting text with all the change markers accepted (delete changes are removed and insert changes are preserved).
    • An optional evaluate parameter, followed by its value, which can be one of the following:
      • dynamic - Evaluates the XPath each time there are changes in the document.
      • dynamic-once - Separately evaluates the XPath for each node that matches the CSS selector. It will not re-evaluate the expression when changes are made to other nodes in the document. This will lead to improved performance, but the displayed content may not be updated to reflect the actual document content.
      • static - If the same XPath is evaluated on several nodes, the result for the first evaluation will be used for all other matches. Use this only if the XPath does not contain a relationship with the node on which the CSS property is evaluated. This will lead to improved performance, but the static displayed content may not be updated to reflect the actual document content.

Note

When XPath expressions are evaluated, the entities and xi:include elements are replaced with the actual content that is referenced. For example, consider the following code snippet:
<article>
  <xi:include href="section1.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
</article>
where section1.xml contains the following content:
<section>
  <p>Referenced content</p>
</section>
The latter will be the actual content in which the XPath expression is executed.

An Example of the oxy_xpath() Function

The following example counts the number of words from a paragraph (including tracked changes) and displays the result in front of it:

para:before{ 
  content: 
   concat("|Number of words:", 
    oxy_xpath(
        "count(tokenize(normalize-space(string-join(text(), '')), ' '))",
        processChangeMarkers,
       true),
    "| "); 
}

Was this helpful?