Sablon.XML.XPath (sablon v0.4.4)

Copy Markdown View Source

A small XPath 1.0 subset, sufficient for every query sablon performs.

Supported: absolute and relative location paths, the // shorthand, the child, self, parent, descendant, descendant-or-self, ancestor, ancestor-or-self and attribute axes, name and wildcard node tests, text()/node(), predicates combining and/or/=/!= and the count/1, not/1, name/0, local-name/0, position/0 and last/0 functions.

Like libxml2, an absolute path is evaluated from the root of the tree the context node belongs to - which for a detached subtree is that subtree itself, not the whole document.

Summary

Functions

Discards the memoised expressions of the current process.

Compiles an expression.

Translates the tiny CSS subset used by sablon (Tag, Tag[attr="value"]) into the equivalent XPath expression.

Runs expression against node.

Functions

clear_cache()

@spec clear_cache() :: :ok

Discards the memoised expressions of the current process.

compile(expression)

@spec compile(binary()) :: term()

Compiles an expression.

The same handful of expressions is evaluated over and over while a document is processed, so compiled forms are memoised per process.

css_to_xpath(selector)

@spec css_to_xpath(binary()) :: binary()

Translates the tiny CSS subset used by sablon (Tag, Tag[attr="value"]) into the equivalent XPath expression.

query(node, expression, namespaces \\ [])

@spec query(Sablon.XML.Node.t(), binary(), keyword() | map()) :: [Sablon.XML.Node.t()]

Runs expression against node.

namespaces optionally maps prefixes used in the expression to namespace URIs; a prefix then also matches document prefixes bound to the same URI.