[lxml-dev] Context of custom XPath functions
Stefan Behnel
stefan_ml at behnel.de
Fri Aug 24 00:05:18 CEST 2007
Hi,
I investigated this a little. It looks like such a context is not as hard to
implement as I first thought. We can just throw an exception for the dangerous
cases for now, so that we can see if people actually use them. And since the
pointer to the libxml2 XPath context is cleared before returning from the
function, we can determine the case where users keep the context alive and
just throw an exception as well.
Frederik Elwert wrote:
> * a node (the context node)
We can instantiate the context Element if it's from the current document, that
should not do any harm.
> * a pair of non-zero positive integers (the context position and
> the context size)
libxml2 makes them available, but since I don't quite get what they are used
for, I'll leave these out for now. (Feel free to convince me that they are
needed).
> * a set of variable bindings
We can get these from libxml2's XPath context by traversing a hash table.
However, I'm not sure how these behave for XSLT, so I'll also just leave these
out for now.
> * a function library
Who cares, really? Just call another XPath expression if you really need to
access an XPath function.
> * the set of namespace declarations in scope for the expression
That's just the nsmap of the context node.
libxml2's XPath context also has a pointer for the value of the here()
function, maybe that's interesting, too.
Ok, so I think it would be enough for now to provide the context with a
property "context_node" and maybe with a call-local dictionary that allows
functions to keep state.
Would that be enough for you?
BTW, this is definitely lxml 2.0 stuff, it won't go into lxml 1.3.
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: function-xpath-context.patch
Type: text/x-diff
Size: 3596 bytes
Desc: not available
Url : http://codespeak.net/pipermail/lxml-dev/attachments/20070824/dc6fc48a/attachment.bin
More information about the lxml-dev
mailing list