Created
November 20, 2015 17:53
-
-
Save eerohele/c972ac425db1b5505f35 to your computer and use it in GitHub Desktop.
Defining a Saxon integrated extension function in Clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Define a Saxon integrated extension function that checks whether | |
; the given element has the given DITA class. | |
; | |
; For example, given: | |
; | |
; <topic id="topic" class="- topic/topic "> ... </topic> | |
; | |
; This XPath function, when defined and aliased under the "dita" | |
; namespace prefix, will return true for that element: | |
; | |
; dita:has-class(., 'topic/topic') | |
(defextfn has-class | |
"http://eerohele.github.io" | |
[[:one :any-node] [:one :string]] | |
[:one :boolean] | |
[el class-name] | |
; predicates/has-class? is an imaginary Clojure function that does the actual work. | |
(XdmAtomicValue. (predicates/has-class? class-name el))) | |
; Register the extension function with Saxon, using the Saxon library for | |
; Clojure (https://github.com/eerohele/saxon): | |
(.registerExtensionFunction saxon/proc has-class) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment