[racket] sxpath, txpath and accessors

From: John Clements (johnbclements at gmail.com)
Date: Tue Mar 3 12:14:42 EST 2015

I think sxpath is not as broken as you think. It certainly *is* desperately
short of examples, and I'll add this one when I'm done.

I wouldn't call this complete success, but after much head-scratching and
doc-reading, I got this to produce the expected result:

(((sxml:preceding (ntype?? 'www)) doc) ((sxpath `(aaa xxx)) doc))
; =>
; '((www "\n" "     " (zzz) "\n" "  ")
;   (www " www content " (xxx) (www "\n" "     " (zzz) "\n" "  ")))


That is, sxml:preceding needs to know about the whole doc (reasonable,
given that it's back-traversing), and it acts as a filter. Is there some
way to turn this around so that the sxml:preceding node appears in the
sxpath chain? There might be, yes. Also, why do I have to use 'ntype??'
instead of sxpath? Not sure.  I think this library might gain a great deal
from being a *teensy* bit less higher-order.

In the end, though... it's true that you might as well just use txpath.

(FYI, I'm planning to use this example in the docs, please let me know if
that's not appropriate.)

Best,

John Clements


On Tue, Mar 3, 2015 at 7:28 AM, Vincent St-Amour <stamourv at ccs.neu.edu>
wrote:

> I have not been able to get those axes working either. I've looked
> briefly at the implementation of `sxml:preceding`, and it's unclear to
> me how it could even work.
>
> Since `txpath` appears to work, I'd stick with that. I'm not sure why
> it's deprecated in favor of `sxpath`. Since, AFAICT, we're just
> packaging that library (i.e. not developing it) and its development
> appears to have stopped, I don't expect `txpath` to go anywhere.
>
> Vincent
>
>
>
> At Tue, 3 Mar 2015 06:56:34 -0500,
> Sanjeev K Sharma wrote:
> >
> > On Mon, Mar 02, 2015 at 09:52:53AM -0500, Vincent St-Amour wrote:
> > > I recommend the short tutorial near the top of this document:
> > >
> > >     http://pkg-build.racket-lang.org/doc/sxml/sxpath.html
> > >
> >
> > Thanks for the suggested solution;
> >
> > that was exactly the document I referred to
> >
> > I have not been able to generate an sxpath working example of the axes
> listed at the bottom of that page.  Aside from generating an example, from
> Oleg's documents to some other google hits I haven't found working examples
> either.
> >
> > a simplified example (including your suggestion)
> >
> > #lang racket (require sxml)(require sxml/html)
> > (define doc(html->xexp
> > "<AAA>
> >    <BBB>
> >       <CCC/>
> >       <www> www content <xxx/><www>
> >       <zzz/>
> >    </BBB>
> >    <XXX>
> >       <DDD> content in ccc
> >       </DDD>
> >    </XXX>
> > </AAA>"))
> >
> > ((txpath"/aaa/xxx/preceding::ccc")doc)
> > ;  '((ccc))
> >
> >
> > ((txpath"/aaa/xxx/preceding::www")doc)
> > ;  '((www "\n" "      " (zzz) "\n" "   ")
> > ;    (www
> > ;     " www content "
> > ;     (xxx)
> > ;     (www "\n" "      " (zzz) "\n" "   ")))
> > ;  '()
> >
> > ((sxpath '(aaa xxx (sxml:preceding '(www)))) doc)
> > ;  '()
> >
> > ((sxpath '(aaa xxx (sxml:preceding (www)))) doc)
> > ;  '()
> >
> > ((sxpath'(aaa xxx (preceding:"www")))doc)
> > ;  '()
> >
> > ((sxpath '(aaa xxx ((sxml::preceding "www")))) doc)
> > ;  '()
> >
> > ((sxml:preceding ((sxpath '(aaa xxx www))))doc)
> > ;  '()
> > ____________________
> >   Racket Users list:
> >   http://lists.racket-lang.org/users
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150303/0212553b/attachment.html>

Posted on the users mailing list.