Andrey Tatarinov wrote:
> Just an interesting thing to think of:
>
> I think that it would be pythonic to treat xslt transformations just as
> other functions, for example:
>
>>>> tr1 = lxml.etree.xslt_fromfile('tr1.xsl')
>>>> tr2 = lxml.etree.xslt_fromstring('''<?xml ...
> ... <!-- transformation here -->
> ... ''')
>>>> data = lxml.etree.parse('data.xml') # maybe .fromfile() ?
>>>> data1 = tr1(data)
>>>> data2 = tr2(data)
>>>> data12 = tr2(tr1(data))
>
> What do you think?
Looks nice. And it would simply require to make XSLT objects callable. Still,
there are two functions in XSLT: apply and tostring, so maybe the right API
would be something like
class XSLT:
def __init__():
"parse and prepare"
def __call__(to_what):
" apply it"
def __str__():
"get the result"
tr55 = XSLT(some_xslt_tree)
xml = str(tr1(tr55(some_xml_tree)))
Stefan
|