- sxml:xpath string #!rest ns-bindingprocedure
- txpath string #!rest ns-bindingprocedure
- sxml:xpath+root string #!rest ns-bindingprocedure
- sxml:xpath+root+vars string #!rest ns-bindingprocedure
Returns a procedure that accepts an SXML document tree and an optional association list of variable bindings and returns a nodeset (list of nodes) that match the XPath expression string.
The optional ns-binding argument is an alist of namespace bindings. It is used to map abbreviated namespace prefixes to full URI strings.
(txpath x) is equivalent to (sxpath x) whenever x is a string. The txpath, sxml:xpath+root and sxml:xpath+root+vars procedures are currently all aliases for sxml:xpath, which exist for backwards compatibility reasons.
It's useful to compare the following examples to the above examples for sxpath.
(import txpath) ;; selects all the 'item' elements that have an 'olist' parent ;; (which is not root) and that are in the same document as the context node ((txpath "//olist/item") '(doc (olist (item "1")) (item "2") (nested (olist (item "3"))))) => ((item "1") (item "3")) ;; Same example as above, but now with a namespace prefix of 'x', ;; which is bound to the namespace "bar" in the ns-binding parameter. ((txpath "//x:olist/item" '((x . "bar"))) '(doc (bar:olist (item "1")) (item "2") (nested (olist (item "3"))))) => ((item "1")) ;; selects only the nth 'item' element under each 'olist' parent ;; (which is not root) and that is in the same document as the context node ;; The n is parameterized to be the first item ((txpath "//olist/item[$n]") '(doc (olist (item "1") (item "2")) (nested (olist (item "3")))) '((n . 1))) => ((item "1") (item "3")) ;; selects the 'chapter' children of the context node that have one or ;; more 'title' children with string-value equal to 'Introduction' ((txpath "chapter[title='Introduction']") '(text (chapter (title "Introduction")) (chapter "No title for this chapter") (chapter (title "Conclusion")))) => ((chapter (title "Introduction")))