[lxml-dev] Keep track of file URL in Elements

Stefan Behnel stefan_ml at behnel.de
Sun Aug 26 17:22:02 CEST 2007


Frederik Elwert wrote:
> XForms turns out to be quite challenging... Sorry to bother you again.
> 
> I need to access a document given by a link in an attribute. When using
> XSLT, this would be a typical usecase for document(). But when not using
> XSLT, I need to mimic it's behaviour, since document() doesn't work in
> ordinary XPath expressions.
> 
> So I have something like this in an XML document:
> 
> <instance resource="default-scales.xml"/>
> 
> Since the link is relative to the document's location, and not to the
> current working directory, I need to get some absolute path for this.
> But the information for the document's location is only stored in the
> ElementTree initially generated by etree.parse(). The descendants know
> neither about the document's location, nor about their "parent"
> ElementTree, as far as I could see.

Doesn't element.getroottree() do what you want?

Stefan


More information about the lxml-dev mailing list