[XML-SIG] 4xslt - passing parameters

Uche Ogbuji uche.ogbuji@fourthought.com
Mon, 11 Nov 2002 00:24:42 -0700


> > > 
> > > Yes, you should be able to do that. How exactly are you invoking the
> > > transformation? If you have a Processor instance proc, and you are calling,
> > > e.g.
> > >   
> > >   proc.runStream(str)
> > >   
> > > then you can simply add the keyword argument topLevelParams with a
> > > dictionary of parameters as its value. For example:
> > > 
> > >   result = proc.runStream(str, topLevelParams={'page': 27})
> > 
> > I'm not sure if this works, though it might (let me know if it does). 
> > The problem is that the key in the dictionary must contain the namespace
> > of the variable as well.  So assuming the variable is referenced as
> > "$page" then the dictionary that is passed in must be:
> > 
> >   {('','page'),27}
> 
> No.  You don't have to pass in a namespace.  BTW, your example is wrong in 
> either case because the empty namespace is None, not '' (I suggest always 
> using xml.dom.EMPTY_NAMESPACE.
> 
> Anyway, Just as XSLT standard parameters default to no namespace if no prefix 
> is used, so do 4XSLT's from the command line.
> 
> It has always been this way.

In a fit of curiousity, I went to 4Suite 0.11.1 and pulled out this old 
snippet from Stylesheet.prime:

        for k in topLevelParams.keys():
            if type(k) != types.TupleType:
                try:
                    split_name = Util.ExpandQName(k, 
namespaces=context.processorNss)
                except KeyError:
                    continue
            else:
                split_name = k
            overridden_params[split_name] = topLevelParams[k]

Ah, nostalgia.  :-)

That having been said, "It has always been this way" is no reason it cannot 
change.  Perhaps we can expect more sophistication from a user of the 
Processor API than we can a Web or command-line user.

But even after a bit of though, I'm not inclined right away to make things 
more restrictive.


-- 
Uche Ogbuji                                    Fourthought, Inc.
http://uche.ogbuji.net    http://4Suite.org    http://fourthought.com
Python&XML column: 2. Introducing PyXML - http://www.xml.com/pub/a/2002/09/25/p
y.html
The Past, Present and Future of Web Services 1 - http://www.webservices.org/ind
ex.php/article/articleview/663/1/24/
The Past, Present and Future of Web Services 2 - 'http://www.webservices.org/in
dex.php/article/articleview/679/1/24/
Serenity through markup - http://adtmag.com/article.asp?id=6807
Tip: Using generators for XML processing - http://www-106.ibm.com/developerwork
s/xml/library/x-tipgenr.html