Hi Marc,

I have not used it, or even claim to understand it, but
https://github.com/jpcs/transform.xq might give you some ideas.
It avoids eval by using an EBNF to  pre-generate an  XPath parser in XQuery.

/Andy



On 13 November 2014 21:51, Marc van Grootel <marc.van.groo...@gmail.com>
wrote:

> Hi,
>
> I would like to ask some advice.
>
> For my Origami[1] library I'm exploring different ways of providing
> more powerful selectors for nodes in a template document.
>
> As this is for a templating library I would like to offer string based
> selectors and am considering if I should go for CSS-style selectors or
> XPath selectors.
>
> I started on CSS selectors to be able to select nodes with selectors
> like "p#id" and "li.class" but to do this properly it involves quite a
> bit of string manipulation in order to support more advanced stuff.
>
> Being in a language that already has XPath in it, it would be much
> more natural and powerful to use XPath selectors. This led me to look
> at xquery:eval.
>
> So far I resisted using eval but the code is a lot simpler that way.
> Implementing CSS-style selectors would probably lead me down a path
> with a lot more ugly string manipulation.
>
> I'm aware that it's better to express these things in XQuery code and
> that is also possible. But it's so much nicer to read this:
>
>   xf:extract(xf:select('li'), $doc)
>
> then this:
>
>   xf:extract(function($node) { $node/li }, $doc)
>
> I'm interested in pros and cons of using xquery:eval with XPath
> string-selectors. How is the performance? Other downsides (such as
> being non-standard)?
>
> Thanks
>
> --Marc
>
> [1] https://github.com/xokomola/origami
>

Reply via email to