Re: [xml] arguments to an XSLT transformation in Python



Daniel Veillard wrote:
On Wed, May 05, 2004 at 08:17:21PM +0200, Martijn Faassen wrote:

This works, but I'd like to pass something else to the transformation (and thus f()) than a string or the result of an xpath expression. What I would to pass is an arbitrary Python object. While the XSLT transformation itself cannot use it, I can pass it to my Python extension function which then should be able to call methods on it.

I can't get this to work though. When I pass in a python object what is passed to f() is an empty list ([]). The only thing that seems to be legal to pass is an xpath expression...


  Hum, yes I think only a string will go through there.

I've gotten the extension function system to segfault pretty easily from Python by the way. I think Python exceptions in extension functions crash the system at present, but I haven't debugged this in detail.

Is something like what I want supported at all? If not, is there a workaround? I need to be able to get to a context object that has nothing to do with XSLT from my Python script. Is it possible to stuff such a thing (before the transformation starts) on what gets passed as ctx, perhaps?

  At the C level you can use the _private field of the context
to plug your own data. Maybe that could be added as a Python interface, but I doubt there is something which would work out of the
box right now ...

Hmmm. Let me describe the problem in a bit more detail:

I have an XSLT transformation to transform some XML into HTML. The XML contains <link> elements, which include a path attribute. This path can be relative or absolute. During the transformation, this path attribute is in fact resolved to some object (in an object database), and then the *absolute* path is placed in the resulting document. So, all relative paths are made absolute. This procedure is necessary because I'm dealing with Zope, which has a funky facility (acquisition) which kicks in when you don't want to, which makes bogus relative URLs work to a certain extent. This 'feature' interacts very badly with bots which thrawl the site, as they get trapped into loops. Which is why we go through this hassle.

One way to solve this is to do a XPath query from python on all links in the document first, then produce an XML document which contains the absolutized links..hm.. well, it all sounds rather complicated compared to having an extension function do it..

In the mythical XSLT 1.1 specification it seems to have been part of the spec to be able to pass external objects on to functions, though I don't know what is defined about passing variables into the XSLT transformation.

Regards,

Martijn



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]