9.0
top
← prev up next →

SXML Misc UtilitiesπŸ”— i

kurinoku

A module that has some sxml functions that might be of use

procedure

( sxml:text* node-or-nodeset)string

node-or-nodeset:(or nodenodeset? )
Like sxml:text , but retrieves all string contents from a node and its children in depth first post order, which is likely the rendered order and the expected one.

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 nodenodeset? )(or/c node#f)))
path:(or/c list? string? )
ns-bindings:(listof (cons/c symbol? string? ))='()
Like sxpath , but when the resulting function is applied, it returns the first element found on a breadth first search or it returns #f.

procedure

( sxpath/e path[ns-bindings])(-> (or/c nodenodeset? )nodeset? )

path:(or/c list? string? )
ns-bindings:(listof (cons/c symbol? string? ))='()

procedure

( sxpath1/e path[ns-bindings])

(-> (or/c nodenodeset? )(or/c node#f))
path:(or/c list? string? )
ns-bindings:(listof (cons/c symbol? string? ))='()
Like sxpath and sxpath1 , but throws exn:fail:sxpath instead of writing the error to (current-error-port ) and returning #f.

procedure

( sxpath* pathdoc[ns-bindings])nodeset?

path:(or/c list? string? )
doc:(or/c nodenodeset? )
ns-bindings:(listof (cons/c symbol? string? ))='()

procedure

( sxpath1* pathdoc[ns-bindings])(or/c node#f)

path:(or/c list? string? )
doc:(or/c nodenodeset? )
ns-bindings:(listof (cons/c symbol? string? ))='()
Equivalent to ((procpathns-bindings)doc) where proc is either sxpath/e or sxpath1/e respectively.

procedure

( node-has-classes? class-lst)sxml-converter

class-lst:(listof (or/c string? symbol? ))
Behaves likes sxml:filter , filters nodes by the elements of its class attribute.

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.

Some examples found in the test suite.
> (define tree
'(body
(div(@(class"mt-2 mb-2")))
(div(@(class"mt-2")))
(div(@(class"mt-2 mb-2 p-1")))))
> ((node-join
(sxpath '(//))
(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? )
Like node-has-classes? , but for only one class.

#:transparent)
Exception thrown by sxpath/e and similar.

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /