Hi Marc, we use xquery:eval a lot. I think that reflexivity in a language is a very powerful and useful tool and in basex it's implemented quite well. The possibility to pass, in the parameter map, function items as parameters besides variables and context builds up a complete toolset allowing one to write elegant and dynamic workflows with very fec lines of code. In all our use cases we haven't encountered any performance issue and now it's even possible to set timeouts on the execution which is pretty handy to limit the time of a RESTXQ service which is something I still don't know how to do without eval. As per your use case, using XPath instead of CSS like selectors is something that I would do and it sounds pretty much reasonable. These are just my two cents. Cheers, M.
On 13/11/2014 22:51, Marc van Grootel 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