[lxml-dev] xpath on text nodes
Jamie Norrish
jamie at artefact.org.nz
Thu Apr 30 22:07:26 CEST 2009
On Thu, 2009-04-30 at 09:42 +0200, Stefan Behnel wrote:
> It would be rarely used, I'd say. What sort of interesting XPath queries
> could you possibly do on a node that doesn't have any children, nor
> attributes, nor a tag name or namespace.
Besides selecting other nodes and values relative to the text? Yes, it
is possible to use text_result.getparent() and proceed from there - but
this has the downside of requiring, for some XPath expressions, the code
to modify the expression based on whether text_result was the text or
tail of its parent, which is annoying.
> Also, XPath queries can return Elements and (special) strings, but
> also plain numbers and boolean values.
> So you'd still not have a common interface for all possible result types.
Well, I'm not really asking for a common interface - only that XPath be
enabled for the results of an XPath expression for text(). This would
bring it into line with XSLT behaviour, for one.
However, I accept that it's not going to be used often, and probably
isn't worth you implementing for that reason.
About using iterwalk: this wouldn't seem (on a quick perusal of the
documentation) to easily allow for me to get the preceding context of
the text result, unless I picked some arbitrary earlier element as the
starting point. What am I missing?
Jamie
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://codespeak.net/pipermail/lxml-dev/attachments/20090501/3013369b/attachment.pgp
More information about the lxml-dev
mailing list