Re: [xslt] Re: passing info from 'apply' to an EntityLoader


On Fri, Dec 10, 2004 at 11:10:43AM -0500, Daniel Veillard wrote:
| Hum, the loader at the libxml2 level has no knowledge of the upper
| layer libxslt. I'm afraid this is not simple even when working at the
| C level with all the control, and probably impossible at the Python
| level. The ctxt passed to the resolver is a parsing context. 

It appears that ctxt and libxslt.transformCtxt(ctxt) is constant for 
every document fetched from a given applyStylesheet call.  Is this true?
If so, is there a way to get at the ctxt passed to the resolver from 
the code that calls applyStylesheet?  I could use an external lookup
table to hold the authorization level.

g_userid = {}

def resolver(URL, ID, ctxt):
    userid = g_userid.get(id(ctxt))

def process():
    ctxt   = style.???
    g_userid[id(ctxt)] = 'tom'
    result = style.applyStylesheet(document, args, ctxt)

Or...  I suppose with each XSLT stylesheet having a few lines of
boilerplate code it could work.  Perhaps...

    def process():
        onetime = md5.md5(str(random.random())).hexdigest()
        g_userid[onetime] = 'tom'
        args = { ... , 'login': login }
        result = style.applyStylesheet(document, args)
        del g_userid[onetime]

And then in the very first line of the stylesheet...

    <xsl:param    name="userid" select="''" />
    <xsl:variable name="login" select="document($userid)" />

With the resolver, 

    def resolver(URL, ID, ctxt):
        userid = g_userid.get(id(ctxt))
        if not userid:
            userid = g_userid.get(URL)
            if not userid:
                return None
            g_userid[id(ctxt)] = userid
            return "<user>%s</user>" % userid

All other document() requests should then succeed...  it'd be nice
if I didn't have to have help from the stylesheet (it creates extra
boilerplate stuff for the XSLT writers).   Hmm.  Is it possible, 
after the XSLT stylesheet parsing is done to "inject" these two
lines into the top of the stylesheet?



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