[Baypiggies] XSLT vs Python for XML manipulation

Ramin Firoozye raminf at gmail.com
Fri May 23 20:14:51 CEST 2008


>>
>> On Thu, May 22, 2008 at 4:41 PM, Stephen McInerney
>> <spmcinerney at hotmail.com> wrote:
>>> Can anyone point me to any good articles discussing the merits and
>>> limitations of XSLT vs Python (or XSLT into Python) for XML
>>> manipulation?
>>>
>>> (I inherited an existing flow using XSLT->PERL and I'm trying to
>>> scope how
>>> to
>>> implement some enhances, what to port, what to reuse. It is
>>> desirable to
>>> share
>>> as much of the existing codebase with other users if possible;
>>> however
>>> clean-coding
>>> everything in Python would be cleanest and most compact. It's hard
>>> to make
>>> the call.)
>>
>> Imagine you're an automotive engineer fresh out of college and you go
>> to work for Mazda which uses a rotary engine.  XSLT is like a rotary
>> engine in that there's nothing else like it.  It's way out in left
>> field.
>>
>> Personally, I like the Genshi templating engine because it's similar
>> enough to a normal templating engine, but it's got a bunch of
>> XSLT-like tricks up its sleeve.
>
> Yeah, the template language has some similar features, and then
> there's also the Transformer API which provides a programatic API for
> XML munging:
>
> http://genshi.edgewall.org/wiki/ApiDocs/genshi.filters.transform
>
> -- Matt

Depends on what your XSLT is doing. Genshi is great for templating but  
XSLT has more oomph when it comes to transformation - especially in  
recursively traversing the tree, and also in its XPath support. Most  
non-trivial XSLT scripts make extensive use of recursion, so if you  
decide to go the Genshi route, your biggest challenge will probably be  
to mimic that functionality. Personally, I'd try to do away with it  
altogether. All that recursion stuff makes the code tough to read and  
understand and (obviously) hard for someone to maintain later.

Also, might want to double-check the Genshi wiki to make sure the  
XPath functions you need are supported. Some of them only work in  
XPath predicates.

Good luck.

--Ramin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20080523/b3bee087/attachment.htm>


More information about the Baypiggies mailing list