Changeset 13373 in project


Ignore:
Timestamp:
02/21/09 00:19:57 (11 years ago)
Author:
sjamaan
Message:

Add docs for the txpath module

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/sxpath

    r13366 r13373  
    1414This egg provides the sxpath-related tools from the sxml-tools available
    1515in the SSAX/SXML Sourceforge project.
     16
     17It is split up in three modules: [[#sxpath|sxpath]], [[#txpath|txpath]]
     18and [[#sxpath-lolevel]]. {{sxpath}} depends on {{txpath}} and both
     19modules depend on {{sxpath-lolevel}}.
    1620
    1721Much documentation is available at
     
    4448URI strings.
    4549
     50It can be useful to compare the following examples to those for
     51[#txpath|txpath].
     52
    4653<examples>
    4754<example>
     
    4956;; selects all the 'item' elements that have an 'olist' parent
    5057;; (which is not root) and that are in the same document as the context node
    51 ;;
    52 ;; XPath equivalent of //olist/item
    53 ;;
    5458((sxpath `(// olist item))
    5559 '(doc (olist (item "1")) (item "2") (nested (olist (item "3")))))
     
    6367;; selects the 'chapter' children of the context node that have one or
    6468;; more 'title' children with string-value equal to 'Introduction'
    65 ;;
    66 ;; XPath equivalent of chapter[title='Introduction']
    67 ;;
    6869(sxpath '((chapter ((equal? (title "Introduction")))))
    6970 '(text  (chapter (title "Introduction"))  (chapter "No title for this chapter")  (chapter (title "Conclusion"))))
     
    7172<result>
    7273((chapter (title "Introduction")))
     74</result>
     75</example>
     76<example>
     77<expr>
     78;; (sxpath string-expr) is equivalent to (txpath string-expr)
     79(sxpath "chapter[title='Introduction']"
     80 '(text  (chapter (title "Introduction"))  (chapter "No title for this chapter")  (chapter (title "Conclusion"))))
     81</expr>
     82<result>
    7383</result>
    7484</example>
     
    117127(("hi" . (span (@ (id "hi")) "there"))
    118128 ("link" . (a (@ (id "link")) "click here")))
     129</result>
     130</example>
     131</examples>
     132
     133== txpath
     134
     135This section documents the txpath interface. This interface is mostly
     136useful for programs that deal exclusively with "legacy" textual XPath
     137queries.
     138
     139<procedure>(txpath string . ns-binding)</procedure>
     140
     141Returns a procedure that accepts an SXML document tree and returns a
     142nodeset (list of nodes) that match the {{path}} expression.
     143
     144The optional {{ns-binding}} argument is an alist of namespace
     145bindings.  It is used to map abbreviated namespace prefixes to full
     146URI strings.
     147
     148{{(txpath x)}} is equivalent to {{(sxpath x)}} whenever {{x}} is a
     149string.
     150
     151It's useful to compare the following examples to the above examples
     152for [#sxpath|sxpath].
     153
     154<examples>
     155<example>
     156<expr>
     157;; selects all the 'item' elements that have an 'olist' parent
     158;; (which is not root) and that are in the same document as the context node
     159((txpath "//olist/item")
     160 '(doc (olist (item "1")) (item "2") (nested (olist (item "3")))))
     161</expr>
     162<result>
     163((item "1") (item "3"))
     164</result>
     165</example>
     166<example>
     167<expr>
     168;; selects the 'chapter' children of the context node that have one or
     169;; more 'title' children with string-value equal to 'Introduction'
     170((txpath "chapter[title='Introduction']")
     171 '(text  (chapter (title "Introduction"))  (chapter "No title for this chapter")  (chapter (title "Conclusion"))))
     172</expr>
     173<result>
     174((chapter (title "Introduction")))
    119175</result>
    120176</example>
Note: See TracChangeset for help on using the changeset viewer.