SXML Misc Utilities
(require sxml/extra-utils) | package: sxml-extra |
A module that has some sxml functions that might be of use
procedure
(sxml:text* node-or-nodeset) → string
node-or-nodeset : (or node nodeset?)
Consider the following
> (define tree '(body (div "a ") (div (div "string ") "in " (div (span "or") "der")))) > (string-join ((sxpath "//text()") tree) "") "a in string deror"
> (sxml:text tree) ""
> (sxml:text* tree) "a string in order"
procedure
(sxpath1 path [ns-bindings])
→ (or/c #f (-> (or/c node nodeset?) (or/c node #f))) path : (or/c list? string?) ns-bindings : (listof (cons/c symbol? string?)) = '()
procedure
(sxpath/e path [ns-bindings]) → (-> (or/c node nodeset?) nodeset?)
path : (or/c list? string?) ns-bindings : (listof (cons/c symbol? string?)) = '()
procedure
(sxpath1/e path [ns-bindings])
→ (-> (or/c node nodeset?) (or/c node #f)) path : (or/c list? string?) ns-bindings : (listof (cons/c symbol? string?)) = '()
procedure
path : (or/c list? string?) doc : (or/c node nodeset?) ns-bindings : (listof (cons/c symbol? string?)) = '()
procedure
path : (or/c list? string?) doc : (or/c node nodeset?) ns-bindings : (listof (cons/c symbol? string?)) = '()
procedure
(node-has-classes? class-lst) → sxml-converter
class-lst : (listof (or/c string? symbol?))
The class attribute is made into a list by means of string-split.
All classes in the list must be present in the node to match.
> (define tree '(body (div (@ (class "mt-2 mb-2"))) (div (@ (class "mt-2"))) (div (@ (class "mt-2 mb-2 p-1")))))
> ((node-join (sxpath '(//)) (node-reduce (sxpath '(div)) (node-has-classes? '("mt-2" "mb-2")))) tree) '((div (@ (class "mt-2 mb-2"))) (div (@ (class "mt-2 mb-2 p-1"))))
> ((sxpath `(// div ,(node-has-classes? '("mt-2" "mb-2")))) tree) '((div (@ (class "mt-2 mb-2"))) (div (@ (class "mt-2 mb-2 p-1"))))
> ((sxpath `(// (div (,(node-has-classes? '("mt-2" "mb-2")))))) tree) '((div (@ (class "mt-2 mb-2"))) (div (@ (class "mt-2 mb-2 p-1"))))
procedure
(node-has-class? class) → sxml-converter
class : (or/c string? symbol?)
struct
(struct exn:fail:sxpath exn:fail () #:transparent)