[lxml-dev] How to access XSLT Parameters Inside an Extension Function?
Stefan Behnel
stefan_ml at behnel.de
Tue Jun 10 21:28:30 CEST 2008
Hi,
Thomas Schraitle wrote:
> I use the DocBook stylesheets very much in combination with xsltproc.
> However, xsltproc doesn't support the DocBook extension functions. These
> create line numbers, get the size of a graphic, etc. You know, these sort
> of things that are very difficult or impossible to deal with XSLT. The
> problem is these extension functions are only implemented for Saxon or
> Xalan.
>
> Well, my idea was to write these in lxml. To do this, I have to stick with
> the number of arguments, unless I change the DocBook stylesheets. My
> dream would be to have a kind of a wrapper for xsltproc which implements
> the extension function.
What about this (totally untested) code snippet:
class DocBoocXSLT(XSLT):
def __init__(self, xslt_input):
extensions = {("ns", "myfunc1") : self.myfunc1}
XSLT.__init__(self, xslt_input, extensions = extensions)
def myfunc1(self, ctxt, a, b, c):
param = self.parameters["someparam"]
...
def __call__(self, *args, **kwargs):
self.parameters = kwargs
return XSLT.__call__(self, *args, **kwargs)
Stefan
More information about the lxml-dev
mailing list