Re: [xml] adding transformContexts to Python



On Thu, Aug 31, 2006 at 03:50:10PM +0100, Nic James Ferrier wrote:
Right now there are some things that you can't do in the Python layer
because it's not possible to pre-create a TransformContext and apply a
transformation with one.

So I thought I'd do this and I just want some sanity checking on the
plan:

- add a function:

    libxslt.newTransformContext(doc, stylesheet)

- add a method to the stylesheet class:

    applyStylesheetUser(self, doc, params, transformContext)


So the method of doing this sort of thing will be:

  stylesheet = libxslt.parseStylesheetFile("somefilename.xslt")
  src_doc = libxml2.parseFile("someotherfilename.xml")
  tc = libxslt.newTransformContext(src_doc, stylesheet)
  result = stylesheet.applyStylesheetUser(src_doc, {}, tc)

During the transformation the transform context will be available to
extension functions and the resolver and so on.

  Okay,


Out of interest, I have 2 reasons for doing this:

1. doing memory recovery of resources created by extension functions

   Extension functions could register resources to be collected in a
   map, keyed by the transform context. When the application is
   finished a clean up routine can be run, collecting everything in
   the map for the transformContext just finished.


2. doing per-transfrom entity resolution

   When the resolver is called it can get the xpathContext of the
   call. Which means that it could make a decision on where to look
   for entitys based on something in the xpathContext.

   This facilitates things like multiple heirarchies of resolution
   sources.

  I agree not everything is available at the python level, usually what
got in was driven by user interest, first myself and then other people.
Patches to fill the gap gratefully accepted (but will be reviewed of
course ;-)

  thanks !

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/



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