Skip to content

Instantly share code, notes, and snippets.

@eerohele
Created November 20, 2015 17:53
Show Gist options
  • Save eerohele/c972ac425db1b5505f35 to your computer and use it in GitHub Desktop.
Save eerohele/c972ac425db1b5505f35 to your computer and use it in GitHub Desktop.
Defining a Saxon integrated extension function in Clojure
; 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