Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19184 > unrolled thread
| Started by | Stefan Behnel <stefan_ml@behnel.de> |
|---|---|
| First post | 2012-01-21 05:56 +0100 |
| Last post | 2012-01-21 05:56 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: etree/lxml/XSLT and dynamic stylesheet variables Stefan Behnel <stefan_ml@behnel.de> - 2012-01-21 05:56 +0100
| From | Stefan Behnel <stefan_ml@behnel.de> |
|---|---|
| Date | 2012-01-21 05:56 +0100 |
| Subject | Re: etree/lxml/XSLT and dynamic stylesheet variables |
| Message-ID | <mailman.4904.1327121806.27778.python-list@python.org> |
Adam Tauno Williams, 20.01.2012 21:38:
> I'm using etree to perform XSLT transforms, such as -
>
> from lxml import etree
> source = etree.parse(self.rfile)
> xslt = etree.fromstring(self._xslt)
> transform = etree.XSLT(xslt)
> result = transform(source)
>
> according to the docs at
> <http://lxml.de/xpathxslt.html#stylesheet-parameters> I can pass a
> dictionary of parameters to transform, such as -
>
> result = transform(doc_root, **{'non-python-identifier': '5'})
>
> Can I pass a dictionary-like object? That doesn't seem to be working.
Yes it does, Python copies it into a plain dict at call time.
> I need to perform dynamic lookup of variables for the stylesheet.
Different story.
> I've subclassed dictionary and overloaded [], get, has_key, and in to
> perform the required lookups; these work in testing. But passing the
> object to transform doesn't work.
You should make the lookup explicit in your XSLT code using an XPath
function. See here:
http://lxml.de/extensions.html
Stefan
Back to top | Article view | comp.lang.python
csiph-web