Liking cljdoc? Tell your friends :D

sigel.xpath.core

Functions for selecting and matching things in an XML file with XPath.

For examples, see the function-specific documentation for each function. The examples assume you've required this namespace:

(require '[sigel.xpath.core :as xpath])

Every function in the sigel.xpath.core namespace that select or match things in an XML document rely on an XPathCompiler.

If you don't pass in your own XPathCompiler as the first argument to a function like that, they use *compiler*.

Use variables in XPath expression or pattern

If you need to use variables in your XPath expression or pattern, you can pass a map of variables as the last argument to your XPath operation.

The map key must implement the QNameable protocol. The value must implement the XMLValue protocol.

If you use variables, you also need to pass in an XPathCompiler as the first argument, because setting a variable mutates the XPathCompiler instance.

Example:

(def my-compiler (xpath/compiler))

(xpath/is? my-compiler "<num>1</num>" "xs:integer(num) * $two eq 2" {:two 2})
Functions for selecting and matching things in an XML file with XPath.

For examples, see the function-specific documentation for each function. The
examples assume you've required this namespace:

```
(require '[sigel.xpath.core :as xpath])
```

Every function in the `sigel.xpath.core` namespace that select or match things
in an XML document rely on an [XPathCompiler].

If you don't pass in your own `XPathCompiler` as the first argument to a
function like that, they use [`*compiler*`][dyn-compiler].

## Use variables in XPath expression or pattern

If you need to use variables in your XPath expression or pattern, you can pass
a map of variables as the last argument to your XPath operation.

The map key must implement the [QNameable] protocol. The value must implement
the [XMLValue] protocol.

If you use variables, you also need to pass in an `XPathCompiler` as the first
argument, because setting a variable mutates the `XPathCompiler` instance.

Example:

```
(def my-compiler (xpath/compiler))

(xpath/is? my-compiler "<num>1</num>" "xs:integer(num) * $two eq 2" {:two 2})
```

[XPathCompiler]: http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/XPathCompiler.html

[dyn-compiler]: sigel.xpath.core.html#var-*compiler*
[xpath-api]: sigel.xpath.core.html

[QNameable]: sigel.protocols.html#var-QNameable
[XMLValue]: sigel.protocols.html#var-XMLValue
raw docstring

*compiler*clj

A default XPath compiler.

If you don't pass in your own XPathCompiler instance when compiling a stylesheet, Sigel uses this instance.

A default XPath compiler.

If you don't pass in your own [XPathCompiler](http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/XPathCompiler.html)
instance when compiling a stylesheet, Sigel uses this instance.
raw docstring

->seqclj

(->seq node)

Return a seq on the nodes in the given document.

Return a seq on the nodes in the given document.
raw docstring

compilerclj

(compiler)
(compiler processor default-namespace-uri namespaces)

Make a new XPathCompiler.

Optionally, give the default namespace and additional namespace declarations you want the XPathCompiler to know about.

Make a new [XPathCompiler](http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/XPathCompiler.html).

Optionally, give the default namespace and additional namespace declarations
you want the XPathCompiler to know about.
raw docstring

declare-namespace!clj

(declare-namespace! compiler ns-decl)
(declare-namespace! compiler prefix uri)

Teach an XPathCompiler about a namespace.

You can give the namespace either as a string prefix and a string URI or as a Namespace record.

Teach an [XPathCompiler](http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/XPathCompiler.html)
about a namespace.

You can give the namespace either as a string prefix and a string URI or
as a Namespace record.
raw docstring

declare-variables!clj

(declare-variables! compiler variables)

Declare variables on an XPathCompiler.

This function does not set the value of a variable. Rather, it tells the XPathCompiler that the value of a variable will be set later.

Declare variables on an [XPathCompiler](http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/XPathCompiler.html).

This function does not set the value of a variable. Rather, it tells the
XPathCompiler that the value of a variable will be set later.
raw docstring

default-namespaceclj

(default-namespace compiler)

Get the default namespace URI of an XPathCompiler.

Get the default namespace URI of an [XPathCompiler](http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/XPathCompiler.html).
raw docstring

early-evaluation-contextclj

(early-evaluation-context static-context)

Make a new XPath evaluation context from a static context.

Make a new XPath evaluation context from a static context.
raw docstring

is?clj

(is? context expression)
(is? compiler context expression bindings)

Given an XML context and an XPath expression, return a boolean that indicates whether the expression evaluates to true in that context.

Optionally, give a map of XPath variable bindings.

Example:

(xpath/is? compiler "<one>1</one>" "xs:int(one) + 2 eq 3")
; => true
Given an XML context and an XPath expression, return a boolean that
indicates whether the expression evaluates to true in that context.

Optionally, give a map of XPath variable bindings.

Example:

```
(xpath/is? compiler "<one>1</one>" "xs:int(one) + 2 eq 3")
; => true
```
raw docstring

matchclj

(match context pattern)
(match compiler context pattern bindings)

Return a sequence of values that match an XPath pattern in the given XML context.

Optionally, give a map of XPath variable bindings.

Example:

(vec (xpath/match "<nums><num>1</num><num>2</num><num>3</num></nums>"
                  "num[xs:int(.) lt 3]"))
;;=>
;;[#object[net.sf.saxon.s9api.XdmNode 0x51912c8 "<num>1</num>"]
;; #object[net.sf.saxon.s9api.XdmNode 0x4cc3057a "<num>2</num>"]]
Return a sequence of values that match an XPath pattern in the given XML
context.

Optionally, give a map of XPath variable bindings.

Example:

```
(vec (xpath/match "<nums><num>1</num><num>2</num><num>3</num></nums>"
                  "num[xs:int(.) lt 3]"))
;;=>
;;[#object[net.sf.saxon.s9api.XdmNode 0x51912c8 "<num>1</num>"]
;; #object[net.sf.saxon.s9api.XdmNode 0x4cc3057a "<num>2</num>"]]
```
raw docstring

matches?clj

(matches? node pattern)
(matches? compiler node pattern bindings)

Check whether a node matches a XPath pattern (compiled with pattern).

Check whether a node matches a XPath pattern (compiled with [[pattern]]).
raw docstring

nsclj

(ns prefix uri)

Create a Namespace record composed of a string prefix and a string URI.

Create a Namespace record composed of a string prefix and a string URI.
raw docstring

package-dataclj

(package-data static-context)

Get the package data of a StaticContext.

Get the package data of a StaticContext.
raw docstring

patternclj

(pattern string)
(pattern compiler string)

Make an XPath pattern from a string.

Make an XPath pattern from a string.
raw docstring

selectclj

(select context expression)
(select compiler context expression bindings)

Return a sequence of values that match an XPath expression in the given XML context.

Example:

(def document "<a><b/><c/></a>")

(xpath/select document "a/b | a/c")

;;=> #object[net.sf.saxon.s9api.XdmValue 0x157cb3cd "<b/>\\n<c/>"]

;; `select` returns an XdmValue, which is an Iterable, so you can use
;; Clojure's seq functions on the result.
(str (.getNodeName (first (xpath/select document "a/b | a/c"))))
;;=> "b"
Return a sequence of values that match an XPath expression in the given
XML context.

Example:

```
(def document "<a><b/><c/></a>")

(xpath/select document "a/b | a/c")

;;=> #object[net.sf.saxon.s9api.XdmValue 0x157cb3cd "<b/>\\n<c/>"]

;; `select` returns an XdmValue, which is an Iterable, so you can use
;; Clojure's seq functions on the result.
(str (.getNodeName (first (xpath/select document "a/b | a/c"))))
;;=> "b"
```
raw docstring

set-default-namespace!clj

(set-default-namespace! compiler uri)

Set the default namespace URI of an XPathCompiler.

Setting the default namespace URI allows you to omit the namespace prefix from your XPath expressions.

Example:

(def my-compiler (xpath/compiler))

(set-default-namespace! my-compiler "bar")

(xpath/select my-compiler "<foo xmlns=\"bar\"><baz/></foo>" "foo/baz")
;;=> #object[net.sf.saxon.s9api.XdmNode 0x2e91fb2b "<baz xmlns=\"bar\"/>"]
Set the default namespace URI of an [XPathCompiler](http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/XPathCompiler.html).

Setting the default namespace URI allows you to omit the namespace prefix from
your XPath expressions.

Example:

```
(def my-compiler (xpath/compiler))

(set-default-namespace! my-compiler "bar")

(xpath/select my-compiler "<foo xmlns=\"bar\"><baz/></foo>" "foo/baz")
;;=> #object[net.sf.saxon.s9api.XdmNode 0x2e91fb2b "<baz xmlns=\"bar\"/>"]
```
raw docstring

set-variableclj

(set-variable selector [name value])

Set a variable on an XPathSelector.

The name of the variable must implement the [[saxon/QNameable]] protocol.

The value of the variable must implement the [[saxon/XmlValue]] protocol.

Set a variable on an [XPathSelector](http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/XPathSelector.html).

The name of the variable must implement the [[saxon/QNameable]] protocol.

The value of the variable must implement the [[saxon/XmlValue]] protocol.
raw docstring

static-contextclj

(static-context compiler)

Get the static context of an XPathCompiler.

Get the static context of an [XPathCompiler](http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/XPathCompiler.html).
raw docstring

value-ofclj

(value-of context expression)
(value-of compiler context expression bindings)

Return the value of an XPath expression evaluated in the given context.

If the value is an atomic value, return the value as a Java object of the equivalent type. If it's a node, get the string value of the node.

Example:

(xpath/value-of "<num>1</num>" "xs:int(num)")
;;=> 1
Return the value of an XPath expression evaluated in the given context.

If the value is an atomic value, return the value as a Java object of the
equivalent type. If it's a node, get the string value of the node.

Example:

```
(xpath/value-of "<num>1</num>" "xs:int(num)")
;;=> 1
```
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close