Sigel is a Clojure interface to the Saxon XSLT and XPath implementations.
Sigel is a Clojure interface to the [Saxon](http://www.saxonica.com) XSLT and XPath implementations.
Facilities for defining Saxon integrated extension functions.
Facilities for defining Saxon [integrated extension functions](http://www.saxonica.com/html/documentation/extensibility/integratedfunctions/).
Protocols for converting Clojure values into objects Saxon understands.
Protocols for converting Clojure values into objects Saxon understands.
A set of utility functions mostly for internal use.
A set of utility functions mostly for internal use.
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*
.
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
A set of reusable XSLT components.
A set of reusable XSLT components.
Write and execute XSLT transformations with Clojure.
Scenario:
xsl:element
.For example, you want to transform this:
<a xmlns="my-ns"/>
To this:
<b xmlns="my-ns"/>
In your XSLT transformation, you want to write something like this:
(xsl/template {:match "a"} [:b])
Instead of this:
(xsl/template {:match "a"}
(xsl/element {:name "b"}))
If you create a literal element with [:b]
, though, clojure.data.xml puts it
into the empty namespace. That means that the XSLT stylesheet Sigel produces
will have this:
<xsl:template match="a">
<!-- note the empty xmlns namespace declaration -->
<b xmlns=""/>
</xsl:template>
When what you actually want is this:
<xsl:template match="a">
<b/>
</xsl:template>
To do that, you must first set up your namespace with
clojure.data.xml/alias-uri
:
(xml/alias-uri 'my-ns "my-ns-uri")
You then need to set the xmlns
attribute of your stylesheet and use the
my-ns
prefix when emitting literal XML elements:
(xsl/stylesheet {:version 3.0 :xmlns "my-ns-uri"}
(xsl/template {:match "a"} [::my-ns/b]))
Write and execute XSLT transformations with Clojure. ## XML namespaces Scenario: - Your source XML document is in an XML namespace. - You want to transform that document with Sigel into the same namespace. - You want to write literal XML elements in your transformation, instead of using `xsl:element`. For example, you want to transform this: ```xml <a xmlns="my-ns"/> ``` To this: ```xml <b xmlns="my-ns"/> ``` In your XSLT transformation, you want to write something like this: ``` (xsl/template {:match "a"} [:b]) ``` Instead of this: ``` (xsl/template {:match "a"} (xsl/element {:name "b"})) ``` If you create a literal element with `[:b]`, though, clojure.data.xml puts it into the empty namespace. That means that the XSLT stylesheet Sigel produces will have this: ```xml <xsl:template match="a"> <!-- note the empty xmlns namespace declaration --> <b xmlns=""/> </xsl:template> ``` When what you actually want is this: ```xml <xsl:template match="a"> <b/> </xsl:template> ``` To do that, you must first set up your namespace with `clojure.data.xml/alias-uri`: ```clojure (xml/alias-uri 'my-ns "my-ns-uri") ``` You then need to set the `xmlns` attribute of your stylesheet and use the `my-ns` prefix when emitting literal XML elements: ```clojure (xsl/stylesheet {:version 3.0 :xmlns "my-ns-uri"} (xsl/template {:match "a"} [::my-ns/b])) ```
Functions for creating XSLT elements.
This namespace declares so many vars that conflict with vars in the Clojure core that you probably want to alias the vars in this namespace.
The docstrings in this file are copied directly from the Saxon documentation.
Functions for creating XSLT elements. This namespace declares so many vars that conflict with vars in the Clojure core that you probably want to alias the vars in this namespace. The docstrings in this file are copied directly from [the Saxon documentation](http://www.saxonica.com/html/documentation/xsl-elements).
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close