[racket] xpath, txpath and accessors

From: Sanjeev K Sharma (throwit1 at gmail.com)
Date: Sat Feb 28 21:11:46 EST 2015

on this page 
~/.racket/6.1.1/pkgs/sxml/sxml/doc/sxml/sxpath.html

I read this:

"Like sxpath, but only accepts an XPath query in string form, using the standard XPath syntax.

Deprecated; use sxpath instead."

so I'd like to get the hang of sxpath but I'm somehow stuck on how to translate txpath syntax to sxpath syntax for axes and accessors

after the example document below are some of the variations I tried

#lang racket (require sxml)(require sxml/html)
(define doc(html->xexp
"<AAA>
   <BBB>
      <CCC/>
      <www> www content <xxx/><www>
      <zzz/>
   </BBB>
   <XXX>
      <DDD>
           <EEE/>
           <FFF>
              <HHH/>
              <GGG>
                 <JJJ>content under jjj
                    <QQQ><lll/>content under qqq</qqq>
                    <rrr/>
                 </JJJ>
                 <JJJ/>
              </GGG>
              <HHH/>
           </FFF>
      </DDD>
   </XXX>
   <CCC>content in ccc 
      <DDD/>
   </CCC>
</AAA>"))


((txpath"/aaa/xxx/preceding::*")doc);expect;'((zzz) ... (www "\n" "      " (zzz) "\n" "   "))))

((txpath"/aaa/xxx/preceding::zzz")doc);expect '((zzz))
((txpath"/aaa/xxx/preceding::www")doc);expect '((www "\n" " ...   " (zzz) "\n" "   ")))
((txpath"/aaa/xxx/preceding::www/following::lll")doc);expect '((lll) (lll))

;from the doc, 
;lists in the s-expression syntax correspond to string concatenation in the txpath syntax.
;((sxpath'(aaa xxx ddd fff ggg jjj qqq))doc);expect '((qqq (lll) "content under qqq"))

((sxpath'(aaa xxx preceding))doc)

((sxpath'(aaa xxx preceding::www))doc)
((sxpath'(aaa xxx preceding::zzz))doc)
((sxpath'(aaa xxx preceding::bbb))doc)

((sxpath'(aaa xxx "preceding"))doc)
((sxpath'(aaa xxx "preceding::zzz"))doc); 
((sxpath'(aaa xxx "preceding::www"))doc); 

((sxpath'(aaa xxx "preceding::*"))doc)
;((sxpath "/aaa/xxx/preceding::*")doc); works 
((sxpath'(aaa xxx preceding::*))doc)
((sxpath'(aaa (xxx (preceding::*))))doc)
((sxpath'(aaa (xxx (preceding::*))))doc)
((sxpath'(aaa (xxx (preceding::"*"))))doc)
((sxpath'(aaa (xxx "preceding::*")))doc)
((sxpath'(aaa (xxx ("preceding::*"))))doc)

((sxpath'(aaa xxx preceding::*))doc)
((sxpath'(aaa xxx preceding::*))doc)
((sxpath'(aaa xxx "preceding::*"))doc)
((sxpath'(aaa xxx ,"preceding::*"))doc)
((sxpath'(// aaa /xxx /"preceding::*"))doc)

;((sxpath'(//aaa /xxx/preceding"::*"))doc); error
;(sxml:preceding::*(sxpath'(aaa xxx))doc); error

((sxml:preceding 'eq) doc) ;#<procedure:...l/sxpath-ext.rkt:578:4>
((sxml:preceding(sxpath'(aaa xxx)))doc);#<procedure:...l/sxpath-ext.rkt:578:4>




I'd like to get the other axes and accessors working but now that I've spent some time on this I also REALLY want to know what my blind spot is here.  Hope I didn't miss something glaringly obvious.



Posted on the users mailing list.