(let ((tree1 '(html (head (title "Slides")) (body (p (@ (align "center")) (table (@ (style "font-size: x-large")) (tr (td (@ (align "right")) "Talks ") (td (@ (align "center")) " = ") (td " slides + transition")) (tr (td) (td (@ (align "center")) " = ") (td " data + control")) (tr (td) (td (@ (align "center")) " = ") (td " programs")))) (ul (li (a (@ (href "slides/slide0001.gif")) "Introduction")) (li (a (@ (href "slides/slide0010.gif")) "Summary")))))) (tree2 '(text (chapter (title "Introduction")) (chapter "No title for this chapter") (chapter (title "Conclusion"))) ) ; Example from a posting "Re: DrScheme and XML", ; Shriram Krishnamurthi, comp.lang.scheme, Nov. 26. 1999. ; http://www.deja.com/getdoc.xp?AN=553507805 (tree3 '(poem (@ (title "The Lovesong of J. Alfred Prufrock") (poet "T. S. Eliot")) (stanza (line "Let us go then, you and I,") (line "When the evening is spread out against the sky") (line "Like a patient etherized upon a table:")) (stanza (line "In the room the women come and go") (line "Talking of Michaelangelo."))))) `(*TOP* (samples (case (@ (id "10") (full "child::para") (abbreviated "para")) ; tree (elem (@) (para (@) "para") (br (@)) "cdata" (para (@) "second par")) ;expected (list (para (@) "para") (para (@) "second par")) (descr "selects the 'para' element children of the context node") (test "(select-kids (ntype?? 'para))") (test (@ (sxpath "yes")) "(para)") ) (case (@ (id "20") (full "child::*") (abbreviated "*")) (elem (@) (para (@) "para") (br (@)) "cdata" (para "second par")) (list (para (@) "para") (br (@)) (para "second par")) (descr "selects all element children of the context node") (test "(select-kids (ntype?? '*))") (test (@ (sxpath "yes")) "(*)")) (case (@ (id "30") (full "child::text()") (abbreviated "text()")) ; tree (elem (@) (para (@) "para") (br (@)) "cdata" (para "second par")) ;expected (list "cdata") (descr "selects all text node children of the context node") (test "(select-kids (ntype?? '*text*))") (test (@ (sxpath "yes")) "(*text*)") ) (case (@ (id "40") (full "child::node()") (abbreviated "node()")) ; tree (elem (@) (para (@) "para") (br (@)) "cdata" (para "second par")) ;expected: (cdr tree) (list (@) (para (@) "para") (br (@)) "cdata" (para "second par")) (descr "selects all the children of the context node, whatever their node type") (test "(select-kids (ntype?? '*any*))") (test (@ (sxpath "yes")) "(*any*)") ) (case (@ (id "50") (full "child::*/child::para") (abbreviated "*/para")) ; tree (elem (@) (para (@) "para") (br (@)) "cdata" (para "second par") (div (@ (name "aa")) (para "third para"))) ;expected (list (para "third para")) (descr "selects all para grandchildren of the context node") (test "(node-join (select-kids (ntype?? '*)) (select-kids (ntype?? 'para)))") (test (@ (sxpath "yes")) "(* para)") ) (case (@ (id "60") (full "attribute::name") (abbreviated "@name")) ; tree (elem (@ (name "elem") (id "idz")) (para (@) "para") (br (@)) "cdata" (para (@) "second par") (div (@ (name "aa")) (para (@) "third para"))) ;expected (list (name "elem")) (descr "selects the 'name' attribute of the context node") (test "(node-join (select-kids (ntype?? '@)) (select-kids (ntype?? 'name)))") (test (@ (sxpath "yes")) "(@ name)") ) (case (@ (id "70") (full "attribute::*") (abbreviated "@*")) ; tree (elem (@ (name "elem") (id "idz")) (para (@) "para") (br (@)) "cdata" (para "second par") (div (@ (name "aa")) (para (@) "third para"))) ;expected (list (name "elem") (id "idz")) (descr "selects all the attributes of the context node") (test "(node-join (select-kids (ntype?? '@)) (select-kids (ntype?? '*)))") (test (@ (sxpath "yes")) "(@ *)") ) (case (@ (id "80") (full "descendant::para") (abbreviated "form: .//para")) ; tree (elem (@ (name "elem") (id "idz")) (para (@) "para") (br (@)) "cdata" (para "second par") (div (@ (name "aa")) (para (@) "third para"))) ;expected (list (para (@) "para") (para "second par") (para (@) "third para")) (descr "selects the 'para' element descendants of the context node") (test "(node-closure (ntype?? 'para))") (test (@ (sxpath "yes")) "(// para)") ) (case (@ (id "90") (full "self::para")) ; tree (elem (@ (name "elem") (id "idz")) (para (@) "para") (br (@)) "cdata" (para "second par") (div (@ (name "aa")) (para (@) "third para"))) ;expected (list) (descr "selects the context node if it is a 'para' element; otherwise selects nothing") (test "(node-self (ntype?? 'para))") ) (case (@ (id "95") (full "self::elem")) ; tree (elem (@ (name "elem") (id "idz")) (para (@) "para") (br (@)) "cdata" (para "second par") (div (@ (name "aa")) (para (@) "third para"))) ;expected (list (elem (@ (name "elem") (id "idz")) (para (@) "para") (br (@)) "cdata" (para "second par") (div (@ (name "aa")) (para (@) "third para")))) (descr "selects the context node if it is an 'elem' element; otherwise selects nothing") (test "(node-self (ntype?? 'elem))") ) (case (@ (id "100") (full "descendant-or-self::node()") (abbreviated "//")) ; tree (para (@ (name "elem") (id "idz")) (para (@) "para") (br (@)) "cdata" (para "second par") (div (@ (name "aa")) (para (@) "third para"))) ; expected (cons tree (append (cdr tree) ; '((@) "para" (@) "second par" ; (@ (name "aa")) ; (para (@) "third para") ; (@) "third para"))) (list (para (@ (name "elem") (id "idz")) (para (@) "para") (br (@)) "cdata" (para "second par") (div (@ (name "aa")) (para (@) "third para"))) (@ (name "elem") (id "idz")) (para (@) "para") (br (@)) "cdata" (para "second par") (div (@ (name "aa")) (para (@) "third para")) (@) "para" (@) "second par" (@ (name "aa")) (para (@) "third para") (@) "third para") (descr "selects the context node, all the children (including attribute nodes) of the context node, and all the children of all the (element) descendants of t he context node. This is almost a powerset of the context node.") (test "(node-or (node-self (ntype?? '*any*)) (node-closure (ntype?? '*any*)))") (test (@ (sxpath "yes")) "(//)") ) (case (@ (id "120") (full "child::div/descendant::para") (abbreviated "div//para")) ; tree (elem (@ (name "elem") (id "idz")) (para (@) "para") (br (@)) "cdata" (para "second par") (div (@ (name "aa")) (para (@) "third para") (div (para "fourth para")))) ;expected (list (para (@) "third para") (para "fourth para")) (descr "selects the 'para' element descendants of the 'div' element children of the context node") (test "(node-join (select-kids (ntype?? 'div)) (node-closure (ntype?? 'para)))") (test (@ (sxpath "yes")) "(div // para)") ) (case (@ (id "125") (full "/descendant::olist/child::item") (abbreviated "//olist/item")) ; tree (doc (olist (item "1")) (item "2") (nested (olist (item "3")))) ;expected (list (item "1") (item "3")) (descr "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") (test "(node-join (node-closure (ntype?? 'olist)) (select-kids (ntype?? 'item)))") (test (@ (sxpath "yes")) "(// olist item)") ) (case (@ (id "130") (full "/descendant::td/attribute::align") (abbreviated "//td/@align")) ; tree ,tree1 ;expected (list (align "right") (align "center") (align "center") (align "center")) (descr "selects 'align' attributes of all 'td' elements") (test "(node-join (node-closure (ntype?? 'td)) (select-kids (ntype?? '@)) (select-kids (ntype?? 'align)))") (test (@ (sxpath "yes")) "(// td @ align)") ) (case (@ (id "140") (full "/descendant::td[attribute::align]") (abbreviated "//td[@align]")) ; tree ,tree1 ;expected (list (td (@ (align "right")) "Talks ") (td (@ (align "center")) " = ") (td (@ (align "center")) " = ") (td (@ (align "center")) " = ")) (descr "selects all 'td' elements that have an attribute 'align'") (test "(node-reduce (node-closure (ntype?? 'td)) (sxml:filter (node-join (select-kids (ntype?? '@)) (select-kids (ntype?? 'align)))))") (test (@ (sxpath "yes")) "(// (td (@ align)))") (test (@ (sxpath "yes")) "(// ((td) (@ align)))") ) (case (@ (id "150") (full "/descendant::td[attribute::align=\"right\"]") (abbreviated "//td[@align=\"right\"]")) ; tree ,tree1 ;expected (list (td (@ (align "right")) "Talks ")) (descr "selects all 'td' elements that have an attribute align=\"right\"") (test "(node-reduce (node-closure (ntype?? 'td)) (sxml:filter (node-join (select-kids (ntype?? '@)) (select-kids (node-equal? '(align \"right\"))))))") (test (@ (sxpath "yes")) "(// (td (@ (equal? (align \"right\")))))") ) (case (@ (id "160") (full "child::para[position()=1]") (abbreviated "para[1]")) ; tree (elem (@ (name "elem") (id "idz")) (para (@) "para") (br (@)) "cdata" (para "second par") (div (@ (name "aa")) (para (@) "third para"))) ;expected (list (para (@) "para")) (descr "selects the first 'para' child of the context node") (test "(node-reduce (select-kids (ntype?? 'para)) (node-pos 1))") (test (@ (sxpath "yes")) "((para 1))") ) ; selects the last para child of the context node (case (@ (id "170") (full "child::para[position()=last()]") (abbreviated "para[last()]")) ; tree (elem (@ (name "elem") (id "idz")) (para (@) "para") (br (@)) "cdata" (para "second par") (div (@ (name "aa")) (para (@) "third para"))) ;expected (list (para "second par")) (descr "selects the last para child of the context node") (test "(node-reduce (select-kids (ntype?? 'para)) (node-pos -1))") (test (@ (sxpath "yes")) "((para -1))") ) (case (@ (id "200") (full "child::table/child::tr[position()=2]/child::td[position()=3]") (abbreviated "table/tr[2]/td[3]")) ; tree (p (@ (align "center")) (table (@ (style "font-size: x-large")) (tr (td (@ (align "right")) "Talks ") (td (@ (align "center")) " = ") (td " slides + transition")) (tr (td) (td (@ (align "center")) " = ") (td " data + control")) (tr (td) (td (@ (align "center")) " = ") (td " programs")))) ;expected (list (td " data + control")) (descr "selects the third td of the second tr of the table") (test "(node-join (select-kids (ntype?? 'table)) (node-reduce (select-kids (ntype?? 'tr)) (node-pos 2)) (node-reduce (select-kids (ntype?? 'td)) (node-pos 3)))") (test (@ (sxpath "yes")) "(table (tr 2) (td 3))") ) (case (@ (id "210") (full "child::para[attribute::type='warning'][position()=5]") (abbreviated "para[@type='warning'][5]")) ; tree (chapter (para "para1") (para (@ (type "warning")) "para 2") (para (@ (type "warning")) "para 3") (para (@ (type "warning")) "para 4") (para (@ (type "warning")) "para 5") (para (@ (type "warning")) "para 6")) ;expected (list (para (@ (type "warning")) "para 6")) (descr "selects the fifth 'para' child of the context node that has a type attribute with value warning") (test "(node-reduce (select-kids (ntype?? 'para)) (sxml:filter (node-join (select-kids (ntype?? '@)) (select-kids (node-equal? '(type \"warning\"))))) (node-pos 5))") (test (@ (sxpath "yes")) "( (((para (@ (equal? (type \"warning\"))))) 5 ) )") ) (case (@ (id "220") (full "child::para[position()=5][attribute::type='warning']") (abbreviated "para[5][@type='warning']")) (chapter (para "para1") (para (@ (type "warning")) "para 2") (para (@ (type "warning")) "para 3") (para (@ (type "warning")) "para 4") (para (@ (type "warning")) "para 5") (para (@ (type "warning")) "para 6")) ;expected (list (para (@ (type "warning")) "para 5")) (descr "selects the fifth 'para' child of the context node if that child has a 'type' attribute with value 'warning'") (test "(node-reduce (select-kids (ntype?? 'para)) (node-pos 5) (sxml:filter (node-join (select-kids (ntype?? '@)) (select-kids (node-equal? '(type \"warning\"))))))") (test (@ (sxpath "yes")) "( (( (para 5)) (@ (equal? (type \"warning\")))))") (test (@ (sxpath "yes")) "( (para 5 (@ (equal? (type \"warning\")))) )") ) (case (@ (id "235") (full "child::chapter[child::title='Introduction']") (abbreviated "chapter[title='Introduction']")) ; tree ,tree2 ;expected (list (chapter (title "Introduction"))) (descr "selects the 'chapter' children of the context node that have one or more 'title' children with string-value equal to 'Introduction'") (test "(node-reduce (select-kids (ntype?? 'chapter)) (sxml:filter (select-kids (node-equal? '(title \"Introduction\")))))") (test (@ (sxpath "yes")) "((chapter ((equal? (title \"Introduction\")))))") ) (case (@ (id "240") (full "child::chapter[child::title]") (abbreviated "chapter[title]")) ; tree ,tree2 ;expected (list (chapter (title "Introduction")) (chapter (title "Conclusion"))) (descr "selects the 'chapter' children of the context node that have one or more 'title' children") (test "(node-reduce (select-kids (ntype?? 'chapter)) (sxml:filter (select-kids (ntype?? 'title))))") (test (@ (sxpath "yes")) "((chapter (title)))") ) ))) ; kl