[Baypiggies] XSLT vs Python for XML manipulation
warren at muse.com
Fri May 23 07:21:25 CEST 2008
Sorry, that I cannot point to any interesting articles that you
haven't already googled on your own. I will point to my own rather
subjective opinion, which may be summarized as: python is fun while
xslt is not. Here's the Hollywood trailer: It's the battle of the
titans! Executable pseudo-code versus those snarky angle brackets.
I'm sure an XSLT or Perl list might have a different take. Here's mine:
What impressed me first about Python is that the language is
implemented as a tree-like dictionary of dictionaries. This maps well
onto XML quite well. So, for fun, I used to elementtree to parse XML
into a dictionary of dictionaries. This was with some help from Jason
Toffaletti, who suggested how to override the Python dict. So, with
little encouragement, two guys were parsing XML into Python
dictionary. Since then, I tweaked Jason's code, got feedback from Alex
Martelli about improvements, and then went really overboard: I wrote a
generic parser and a xpath like query into a dictionary of
dictionaries. The results are at http://muse.com/tr3/code/py/
This is not to suggest that the code will solve your problems. In
fact, it is with great trepedation that I post something so premature.
But, a quick glance will bear out the point that at least one guy went
really overboard in regards to something that may resemble your type
of problem. That is because Python is a pure joy to use. It is
idiomatic to trees. And that combination inspires others to go
overboard in regard to manipulating XML. Mileage may vary.
On May 22, 2008, at 6:23 PM, Shannon -jj Behrens wrote:
> 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
>> (I inherited an existing flow using XSLT->PERL and I'm trying to
>> scope how
>> implement some enhances, what to port, what to reuse. It is
>> desirable to
>> as much of the existing codebase with other users if possible;
>> 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
> 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.
> However, I digress, and I doubt Genshi will help your situation.
> People either like or hate XSLT. You're just going to have to find
> out whether you like or hate it. Personally, I've turned down every
> company so far that wanted me to use XSLT, but I could be unfairly
> paranoid. The only way you're going to get away from it is via
> rewriting a lot of code, and that has its own extreme dangers. If I
> were in your shoes, I'd see if I could wrap my head around it and just
> make it work.
> I, for one, welcome our new Facebook overlords!
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
More information about the Baypiggies