(absolute-child-number snl) |
Returns one plus the number of nodes preceding snl. This is similar to child-number, but it also counts siblings with a GI different from that of snl.
;; -- Similar to child-number, but also counts siblings with a GI
;; -- different than that of 'snl'.
(define (absolute-child-number snl)
(+ 1 (node-list-length (preced snl))) ) |
(ancestor-member snl gilist) |
Returns the node that is the first ancestor of snl (including snl itself) whose GI is in the gilist list of strings, otherwise returns an empty node list.
(define (ancestor-member snl gilist)
;; Return the first ancestor of nd whose GI is in gilist
(if (node-list-empty? snl)
(empty-node-list)
(if (member (gi snl) gilist)
nd
(ancestror-member (parent snl) gilist)))) |
Returns a node-list containing all ancestors
of nl.
The DSSSL standard has a typo in the definition of the
function ancestors. The following is the
corrected logic -- the third last line used to read
"(loop (parent snl)" which caused an infinite loop.
(define (ancestors nl)
(node-list-map (lambda (snl)
(let loop ((cur (parent snl))
(result (empty-node-list)))
(if (node-list-empty? cur)
result
(loop (parent cur)
(node-list cur result)))))
nl)) |
(get-str-attr attr-nm osnl) |
Returns the string value of attribute attr-nm of
node osnl. Returns "ERROR: ..." if attr-nm
is not defined at osnl.
(define (get-string-attr attr-nm #!optional (osnl (current-node)))
(or (attribute-string attr-nm osnl)
(string-append "ERROR: No Attr " attr-nm) )) |
(get-str-attr-no-err attr-nm osnl) |
Returns the string value of attribute attr-nm of
node osnl. Returns an empty string if attr-nm
is not defined at osnl.
(define (get-str-attr-no-err attr-nm #!optional (osnl (current-node)))
(or (attribute-string attr-nm osnl) "") ) |
(get-numeric-attr attr-nm osnl) |
Returns the numeric value of attribute attr-nm of
node osnl. Returns -1 if attr-nm is not
defined at osnl.
(define (get-numeric-attr attr-nm #!optional (osnl (current-node)))
(let ((a-str (attribute-string attr-nm osnl)))
(if a-str (string->number a-str) -1) )) |
(has-ancestor-member? nd gilist) |
Returns #t if the nd node has an ancestor whose GI is included in the gilist list of strings.
(define (has-ancestor-member? nd gilist)
;; Return #t if nd has an ancestor in gilist
(node-list-empty? (ancestor-member nd gilist))) |
Returns #t if snl has a child node with GI
gi. Returns #f otherwise.
(define (has-child? gi snl)
(not (node-list-empty? (select-elements gi (children snl)))) ) |
(map-node-list->list f nl) |
Returns a list that is the result of mapping procedure f over node-list nl.
;; Map function `f' over node list `nl', returning an ordinary list.
;; (No node list constructor in Jade.)
(define (map-node-list->list f nl)
(if (node-list-empty? nl)
'()
(cons (f (node-list-first nl))
(map-node-list->list f (node-list-rest nl))))) |
(match-element? pattern snl) |
This is a standard DSSSL procedure not currently available in Jade.
See section 10.2.5 of the DSSSL standard for complete semantics of this
function.
(define (match-element? pattern snl)
(if (node-list-empty? (select-elements snl pattern)) #f #t) ) |
Returns a node-list of siblings of osnl, or of the current node if osnl is not specified, with the same GI as the node.
;; Node list of siblings with the same GI as node
(define (matching-siblings #!optional (node (current-node)))
(select-elements (siblings node) (gi node))) |
(next-matching-node osnl) |
Returns either the following sibling with the same GI as osnl (or of the current node if osnl is not supplied) or an empty node-list if there is no following matching sibling.
;; Return the following sibling with the same GI as `node' (or the
;; empty node list if none found).
(define (next-matching-node #!optional (node (current-node)))
(node-list-ref (matching-siblings)
(child-number))) |
(node-list-filter-by-gi nodelist gilist) |
Returns the node list of the elements in the node-list node list whose GI is included in the gilist list of strings.
(define (node-list-filter-by-gi nodelist gilist)
;; Returns the node-list that contains every element of the original
;; nodelist whose gi is in gilist
(let loop ((result (empty-node-list)) (nl nodelist))
(if (node-list-empty? nl)
result
(if (member (gi (node-list-first nl)) gilist)
(loop (node-list result (node-list-first nl))
(node-list-rest nl))
(loop result (node-list-rest nl)))))) |
(prev-matching-node osnl) |
Returns either the previous sibling with the same GI as osnl (or of the current node if osnl is not supplied) or an empty node-list if there is no previous matching sibling.
;; Return the preceding sibling with the same GI as `node' or the
;; empty node list.
(define (prev-matching-node #!optional (osnl (current-node)))
(node-list-ref (matching-siblings)
(- (child-number osnl) 2))) |
Returns either a singleton node-list containing the previous sibling of osnl, or an empty node-list if osnl is the first sibling.
;; In the absence of the full node machinery, return the preceding
;; sibling of `node' which is an element (or the empty node list if
;; none found).
(define (previous-element #!optional (node (current-node)))
;; cdr down the siblings keeping track of the last element node
;; visited and check the current car against `node'; if it matches,
;; return the noted previous.
(let ((first (node-list-first (siblings))))
(let loop ((previous (if (gi first)
first
(empty-node-list)))
(current (node-list-rest (siblings))))
(cond ((node-list-empty? current)
(empty-node-list))
((node-list=? node (node-list-first current)) ; got it
previous)
(else (loop (if (gi (node-list-first current))
(node-list-first current)
previous)
(node-list-rest current))))))) |
Returns a node-list containing the siblings of osnl, including osnl itself.
(define (siblings #!optional (osnl (current-node)))
(children (parent osnl))) |