Hi!
I need to generate source code (mainly Java) from a domain specific XML
language, preferably from within a Python environment (since that's where the
XML is generated).
I tried using XSLT, but I found that I need a template system that supports
Python interaction. I know, lxml's XSLT support is /somewhat/ getting there,
but even with that, XSLT is so clumsy when it comes to code generation
(looping constructs and if/else above all), that it would take me tons of XSLT
code to write what I want.
I've been looking through Python templating systems all over the place, but I
just can't find one that supports XPath - which is by far the best thing to
have when you generate stuff from XML. TAL might be able to get me part of the
way (at least, it supports some kind of Path expressions, though only for
object access), but the only available implementation is part of Zope and I
can't make my code depend on Zope only for a template system.
My problem is that I want to write as little Python code as possible to make
the templates (almost) stand alone and thus readable without the backend code.
I can transform the XML language to a more usable XML format beforehand, no
problem, but I then need to access the result from the template - and that's
almost impossible without XPath.
Does anyone have an idea what I could use? Any hints are helpful.
Thanks,
Stefan 3 1900
Stefan Behnel wrote: Hi!
I need to generate source code (mainly Java) from a domain specific XML language, preferably from within a Python environment (since that's where the XML is generated).
I tried using XSLT, but I found that I need a template system that supports Python interaction. I know, lxml's XSLT support is /somewhat/ getting there, but even with that, XSLT is so clumsy when it comes to code generation (looping constructs and if/else above all), that it would take me tons of XSLT code to write what I want.
I've been looking through Python templating systems all over the place, but I just can't find one that supports XPath - which is by far the best thing to have when you generate stuff from XML. TAL might be able to get me part of the way (at least, it supports some kind of Path expressions, though only for object access), but the only available implementation is part of Zope and I can't make my code depend on Zope only for a template system.
Zope's implementation can be used freestanding AFAIK. There's also
SimpleTal that is totally independant from Zope.
My problem is that I want to write as little Python code as possible to make the templates (almost) stand alone and thus readable without the backend code. I can transform the XML language to a more usable XML format beforehand, no problem, but I then need to access the result from the template - and that's almost impossible without XPath.
Does anyone have an idea what I could use? Any hints are helpful.
Perhaps a TAL + elementTree combo could do ? (first parse the source XML
with elementTree, then pass the resulting tree as the context of the
ZPT/SimpleTal template)
My 2 cents
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
bruno at modulix wrote: Stefan Behnel wrote: I need to generate source code (mainly Java) from a domain specific XML language, preferably from within a Python environment (since that's where the XML is generated).
I tried using XSLT, but I found that I need a template system that supports Python interaction. I know, lxml's XSLT support is /somewhat/ getting there, but even with that, XSLT is so clumsy when it comes to code generation (looping constructs and if/else above all), that it would take me tons of XSLT code to write what I want.
I've been looking through Python templating systems all over the place, but I just can't find one that supports XPath - which is by far the best thing to have when you generate stuff from XML. TAL might be able to get me part of the way (at least, it supports some kind of Path expressions, though only for object access), but the only available implementation is part of Zope and I can't make my code depend on Zope only for a template system.
Zope's implementation can be used freestanding AFAIK. There's also SimpleTal that is totally independant from Zope.
Thanks for the quick reply. I didn't know about SimpleTAL. My problem is that I want to write as little Python code as possible to make the templates (almost) stand alone and thus readable without the backend code. I can transform the XML language to a more usable XML format beforehand, no problem, but I then need to access the result from the template - and that's almost impossible without XPath.
Does anyone have an idea what I could use? Any hints are helpful.
Perhaps a TAL + elementTree combo could do ? (first parse the source XML with elementTree, then pass the resulting tree as the context of the ZPT/SimpleTal template)
SimpleTAL has ElementTree integration. Wouldn't work with lxml, though, as it
uses internals of ElementTree. Problem is that SimpleTAL requires the tree as
a context object, which is difficult to produce from lxml. It should work when
relying on Python code for access, although that removes some of the beauty.
I'll have to see where that gets me...
Thanks,
Stefan
Stefan Behnel wrote: I've been looking through Python templating systems all over the place, but I just can't find one that supports XPath - which is by far the best thing to have when you generate stuff from XML. TAL might be able to get me part of the way (at least, it supports some kind of Path expressions, though only for object access), but the only available implementation is part of Zope and I can't make my code depend on Zope only for a template system.
I have done a lot of text file generation in Jython and Java using
dom4j as the data model and Velocity as the template engine. It's a
very powerful combination.
dom4j elements have XPath accessors so you can say for example
myElement.selectNodes('some/xpath'). Velocity supports introspection on
its data so in a template I can say
#foreach $item ($parent.selectNodes("some/xpath"))
(my syntax may be a little off, this is from memory)
ISTM you should be able to do the same thing from CPython with a dom
model that has XPath accessors and a template engine that supports
calling methods on its data. I think lxml and Cheetah, among others,
would work this way.
Kent This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Oplec |
last post by:
Hi,
I'm learning C++ as a hobby using The C++ Programming Language : Special
Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that
deal with templates. Exercise 13.9 asks for me...
|
by: 42 |
last post by:
I implemented a simple class inherited from Page to create a page
template. It simply wraps some trivial html around the inherited page,
and puts the inherited page into a form.
The problem I...
|
by: Kelly Bert Manning |
last post by:
The discussion in the Utilities manual under working with GDGs says:
| TEMPLATE DSN operands support both GDG absolute version references and
| relative references. DB2 detects the absence of a...
|
by: Chris Lieb |
last post by:
I am new to XML Schema and am running into a bit of a snag. I have
defined an XML-based scripting language for an updater program that I
am working on. I would like to make a schema for this...
|
by: Sergey Dubinets |
last post by:
In effort to prioritize our goals we composed the list of random features
each of them may add value to set of XSLT tools offered from Microsoft.
1. XSLTc (Compiler for XSLT...
|
by: tthunder |
last post by:
Hi @all,
I am looking for a good (compiler-independent) way to generate
meaningful error messages, if specific (unintended) templates are
instantiated.
e.g.
------------
|
by: charles.lobo |
last post by:
Hi,
I have recently begun using templates in C++ and have found it to be
quite useful. However, hearing stories of code bloat and assorted
problems I decided to write a couple of small programs...
|
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= |
last post by:
Hi;
We have a TreeView that represents an xml file (or it's schema is a more
accurate statement). We want to have a double click on a node in the tree
generate the XPath to get to that node.
...
|
by: luthriaajay |
last post by:
I need some help to extract the LatestFillQuantity element value using XPATH.
in Java.
I am unable to extract the value of 10000.
Please help as to what have I done wrong.?
Help appreciated.
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |