XPathQuery

Type: String

XPath and XQuery are the preferred way of traversing a DOM in Fonto. Using XQuery, you can easily look up a node, search for an attribute, create an element structure, or compare the textual content of nodes.

XPath and XQuery can be tested using the XPath test app, which can be found at https://xpath.playground.fontoxml.com.

See the XPath 3.1 and the XQuery 3.1 spec for more information.

The implementation used by Fonto is open source, it can be found at the github page.

Example

1 + 1

Example

declare function local:fingerprint ($node) {
  typeswitch ($node)
    case element() return name($node)
    default return string($node)
};

for $node in child::node() return local:fingerprint($node)

Example

<an-xml-element>{
for $node in child::node() return <a-child>{$node}</a-child>
}</an-xml-element>

Example

(:~
 : It is even possible to use XQuery update facility here,
 : as long as they only use the copy/modify/return syntax:
~:)
for $e in //employee[skill = "Java"]
return
  copy $je := $e
  modify delete node $je/salary
  return $je