Dirk Rothe | 1 Feb 16:58
Picon
Favicon
Gravatar

Re: exslt functions in xpath expressions

done: https://bugs.launchpad.net/lxml/+bug/515553

On Sat, 30 Jan 2010 17:10:25 +0100, Stefan Behnel <stefan_ml <at> behnel.de>  
wrote:

>
> Dirk Rothe, 30.01.2010 16:14:
>> In [9]: print tree.xpath("/a[@b=str:split('12 34')]", namespaces={'str':
>> "http://exslt.org/strings"})
>> [...]
>> XPathEvalError: Unregistered function
>
> You're right, they are currently only available to XSLT. It seems that at
> least the date, math, sets and string functions can be enabled in plain
> XPath, but only from libxslt 1.1.25 onwards. That version was released on
> 2009-09-17, so it's fairly recent.
>
> http://xmlsoft.org/XSLT/EXSLT/html/libexslt-exslt.html
>
> Could you file a feature request for this in the bug tracker? I should be
> able to add support in lxml 2.3.
>
> Stefan
Stefan Behnel | 1 Feb 20:18
Picon
Favicon
Gravatar

Re: ElementTree 1.3a xpath position broken?


Richard Baron Penman, 31.01.2010 14:56:
>>> I am after xpath support for an application running on Google App Engine,
>>> which unfortunately rules out lxml.
>> Yeah, I know. That's one of the reasons I never found a use for the GAE on
>> my side. That also makes your e-mail somewhat misplaced on this list. ;)
> 
> Hopefully the lxml feature request goes somewhere:
> http://code.google.com/p/googleappengine/issues/detail?id=18

Intestering. Yes, let's see what that gives. Everyone's invited to vote for
that bug, obviously.

> Can you recommend an alternative for discussing ElementTree?
> I tried emailing Fredrik earlier but didn't get a response and the
> ElementTree repository hasn't been committed to since 2007.

Fredrik is rather packed with other stuff these days.

Note that ET 1.3 may make it into 3.2/2.7:

http://bugs.python.org/issue1143

So c.l.py and the Python bug tracker are suitable places. For
implementation specific questions, there is also python-dev and the stdlib
sig mailing list.

> http://sourceforge.net/projects/pdis-xpath/
>> I never tried it, but it's been recently updated, so it looks like it's
>> still maintained.
(Continue reading)

Picon

Re: ElementTree 1.3a xpath position broken?

On Tue, Feb 2, 2010 at 6:18 AM, Stefan Behnel <stefan_ml <at> behnel.de> wrote:

Fredrik is rather packed with other stuff these days.

Note that ET 1.3 may make it into 3.2/2.7:

http://bugs.python.org/issue1143

hmm, not sure that is a good idea if ET was not maintained recently.
 

> http://sourceforge.net/projects/pdis-xpath/
>> I never tried it, but it's been recently updated, so it looks like it's
>> still maintained.
>>
>
> That project does look promising, however it doesn't yet support // or ..

I believe that it lacks support for '..' (although that's trivial to
implement even with ET), but '//'???

Yep - no // support.
And I found out (from Ken Riley) that pdis is no longer maintained.

 
> I found it was half implemented and finished it off. There is some elegant
> code in ElementPath.py but it needs refactoring...

Care to provide a patch?

To who? Fredrik seems busy...
So I plan to fork ElementPath.py with my own updates and then release as a standalone ElementTree xpath library like pdis. Also I aim to add support for absolute xpaths, for compatibility with my existing lxml dependent code.

Richard
_______________________________________________
lxml-dev mailing list
lxml-dev <at> codespeak.net
http://codespeak.net/mailman/listinfo/lxml-dev
Stefan Behnel | 2 Feb 09:20
Picon
Favicon
Gravatar

Re: ElementTree 1.3a xpath position broken?


Richard Baron Penman, 02.02.2010 01:56:
> On Tue, Feb 2, 2010 at 6:18 AM, Stefan Behnel wrote:
>>> I found it was half implemented and finished it off. There is some
>>> elegant code in ElementPath.py but it needs refactoring...
>>
>> Care to provide a patch?
> 
> To who? Fredrik seems busy...

To lxml - remember what list we have this discussion on?

Also, to the Python bug tracker. I doubt that a new feature like this would
be rejected.

> So I plan to fork ElementPath.py with my own updates and then release as a
> standalone ElementTree xpath library like pdis. Also I aim to add support
> for absolute xpaths, for compatibility with my existing lxml dependent code.

That's also an option, and a good one IMHO. That would make it easily
available to both ET and lxml. (Advantage for lxml being the incremental
search support which is not available in XPath).

Please take a look at both implementations, the one in ET 1.3 and the one
in lxml.

http://codespeak.net/svn/lxml/trunk/src/lxml/_elementpath.py

There are some minor differences that make the latter one run faster on top
of lxml's advanced tree iterators.

Stefan
jholg | 4 Feb 00:33
Picon
Picon

Re: [Bug 488222] Feature request: add better schematron support to lxml


> > This speaks for pulling the result accessor into the Schematron class,
> probably as a class attribute that can be overridden on an instance level.
> > 
> > The same might make sense for the iso-schematron implementation xsl
> transformation steps.
> 
> Sounds like a much better interface. Any interesting global options would
> be better overridden by subtyping the validator class, so class attributes
> make sense to me.

Committed to trunk:
https://codespeak.net/viewvc/?view=rev&revision=71090

This simply exposes the skeleton xslt steps and the validation result xpath as class attributes.

I consider the iso-schematron works pretty much finished for now...

Holger

--

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
Picon
Gravatar

Get the xml-stylesheet processing instruction

Hi,


I had a hard time tracking this info down (only figured out after reading the thread at http://codespeak.net/pipermail/lxml-dev/2006-September/001903.html), so posted a recipe:

Feel free to use or copy for any purpose.

Thanks,
David

--
David Chandek-Stark
dchandekstark (at) gmail (dot) com
_______________________________________________
lxml-dev mailing list
lxml-dev <at> codespeak.net
http://codespeak.net/mailman/listinfo/lxml-dev
Emanuele D'Arrigo | 5 Feb 21:02
Picon

Re: Get the xml-stylesheet processing instruction

On 5 February 2010 18:38, David Chandek-Stark <dchandekstark <at> gmail.com> wrote:
I had a hard time tracking this info down (only figured out after reading the thread at http://codespeak.net/pipermail/lxml-dev/2006-September/001903.html), so posted a recipe:


True, obtaining PIs (and comments) is not exactly intuitive nor straightforward (in, fact for head-of-file PIs it's straightbackward!! =) ). I guess ideally there could be a list of them available via read-only properties on the tree object, i.e.: docTree.PIs and docTree.comments.

Manu
_______________________________________________
lxml-dev mailing list
lxml-dev <at> codespeak.net
http://codespeak.net/mailman/listinfo/lxml-dev
John Krukoff | 5 Feb 21:58
Favicon

Re: Get the xml-stylesheet processing instruction

On Fri, 2010-02-05 at 20:02 +0000, Emanuele D'Arrigo wrote:
<snip>

> True, obtaining PIs (and comments) is not exactly intuitive nor
> straightforward (in, fact for head-of-file PIs it's straightbackward!!
> =) ). I guess ideally there could be a list of them available via
> read-only properties on the tree object, i.e.: docTree.PIs and
> docTree.comments.
> 
> Manu

I agree, although my version of ideally would be for the ElementTree class 
to do a better imitation of being a root node, so that something simple 
like this would work for looping over all root level nodes:

>>> from lxml import etree
>>> x = etree.XML( '<!--Comment--><?PI?><root/>' )
>>> t = x.getroottree()
>>> list( t )
[<!--Comment-->, <?PI?>, <Element root at 872f66c>]

Or if ElementTree even supported just getchildren() to retrieve the same
data. Even more ideally ;) it'd support insert/append/replace/remove and
company for editing such root level elements. Oh yeah, and if
xpath( '/' ) returned said extended ElementTree as the root node, as
long as I'm wishing for ponies and unicorns.

I suppose the reason it's hard is because effbot's ElementTree hasn't
ever dealt with the issue of non-element root level contents.

--

-- 
John Krukoff <jkrukoff <at> ltgc.com>
Land Title Guarantee Company
Martin Aspeli | 6 Feb 12:46
Picon

Copying children including text nodes

Hi,

I have two trees that were parsed with the HTML parser. The source tree is:

<html>
<head>
<body>
     Foo
     <p>Bar</p>
     Baz
</body>
</html>

The target is:

<html>
<head>
<body>
     <div id="target">Placeholder</div>
</body>
</html>

Now, I want to replace the whole of <div id="target"> tag (so, the tag 
and its children) with the *contents* of the <body> tag in the source 
tree. I obviously don't want the body tag itself.

Performance is important. Also, I don't care about the source tree after 
I'm done, so if "moving" rather than copying makes things faster/easier, 
that's OK.

What's the best way to do this? My naive approach was to do this:

sourceBody = source.find('body')
for sourceBodyChild in sourceBody:
	targetPlaceholder.addnext(sourceBodyChild)
targetPlaceholder.getparent().remove(targetPlaceholder)

However, this loses the text ("Foo"). I guess this is one case where 
dealing with text nodes explicitly would actually be better. :)

Martin

--

-- 
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book
Antti Kaihola | 8 Feb 11:11
Picon

Typo in exception message

Hi,


I'm catching exceptions from cssselect and my code needs to make decisions based on not only exception classes but also the particular exception messages.

The word "pseudo" is mistyped as "psuedo" in four different exceptions. Are these typos going to be kept unchanged for good, or should my code be prepared to match a corrected version as well?

The same typo seems to occur on the lxml web pages as well, by the way.


Regards,

Antti Kaihola
Espoo, Finland

_______________________________________________
lxml-dev mailing list
lxml-dev <at> codespeak.net
http://codespeak.net/mailman/listinfo/lxml-dev

Gmane