Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19168

etree/lxml/XSLT and dynamic stylesheet variables

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <awilliam@whitemice.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'transform': 0.07; 'python': 0.08; '[],': 0.09; 'object?': 0.09; 'developer': 0.12; 'adam': 0.16; 'from:addr:awilliam': 0.16; 'from:addr:whitemice.org': 0.16; 'from:name:adam tauno williams': 0.16; 'lookup': 0.16; 'overloaded': 0.16; 'received:72.14.190': 0.16; 'received:72.14.190.87': 0.16; 'received:mail.wmmi.net': 0.16; 'received:wmmi.net': 0.16; 'reply-to:addr:awilliam': 0.16; 'reply-to:addr:whitemice.org': 0.16; 'subject:lxml': 0.16; 'url:lxml': 0.16; 'values?': 0.16; 'alternate': 0.18; 'working.': 0.18; "doesn't": 0.22; 'dictionary': 0.23; 'parameters': 0.25; 'import': 0.27; "i'm": 0.27; 'variable': 0.27; 'work.': 0.28; 'pass': 0.28; 'seem': 0.29; 'received:72.14': 0.29; "i've": 0.31; 'source': 0.32; "isn't": 0.32; 'to:addr:python-list': 0.33; 'object': 0.33; 'there': 0.33; 'calling': 0.34; 'subject:/': 0.34; 'variables': 0.36; 'but': 0.37; 'using': 0.37; 'received:192': 0.38; 'received:192.168.1': 0.39; 'to:addr:python.org': 0.40; 'url:us': 0.60; 'according': 0.60; 'back': 0.62; 'williams': 0.63; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'xslt': 0.84
Subject etree/lxml/XSLT and dynamic stylesheet variables
From Adam Tauno Williams <awilliam@whitemice.org>
To python-list@python.org
Date Fri, 20 Jan 2012 15:38:11 -0500
Content-Type text/plain; charset="UTF-8"
X-Mailer Evolution 3.2.1
Content-Transfer-Encoding 7bit
Mime-Version 1.0
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To awilliam@whitemice.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4896.1327093938.27778.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1327093938 news.xs4all.nl 6984 [2001:888:2000:d::a6]:51004
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19168

Show key headers only | View raw


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.
I need to perform dynamic lookup of variables for the stylesheet.

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.

If that isn't possible is there an alternate XSLT implementation for
python that would allow calling back for variable values?

-- 
System & Network Administrator [ LPI & NCLA ]
<http://www.whitemiceconsulting.com>
OpenGroupware Developer <http://www.opengroupware.us>
Adam Tauno Williams

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

etree/lxml/XSLT and dynamic stylesheet variables Adam Tauno Williams <awilliam@whitemice.org> - 2012-01-20 15:38 -0500

csiph-web