[xml] adding transformContexts to Python

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

- 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.

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

Nic Ferrier
http://www.tapsellferrier.co.uk   for all your tapsell ferrier needs

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