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 1922
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.selec tNodes('some/xpath'). Velocity supports introspection on
its data so in a template I can say
#foreach $item ($parent.select Nodes("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 to turn a previously
made String class that deals with char's into a templated String class
that uses the template parameter C instead of char. I thought it would
be fairly simple to do this exercise, but I encoutered many errors for
my...
|
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 have run into is that the emitted html at the end of the
process is slightly different and doesn't work.
Please don't be put off by all the source code. All the guts are in this
first base class, and it doesn't do much. The rest is trivial...
|
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 GDG base and creates it,
| with a limit of 99 entries, by default.
I coded GDGLIMIT as (27), so the discussion about coding (0) to suppress
this shouldn't apply.
When I add a new Tablespace Image Copy to an existing stack I like to have
|
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 language since
malformed XML documents break the updater. (I did not have time to add
good error-handling code, so run-time errors can abound if the document
is malformed.)
A sample doc might look something like this:
<manifest>
|
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 stylesheets, that generates .NET
assemblies)
2. Performance improvements in the XslCompiledTransform
| |
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 to check. What I
expected was that there would be minor code bloat and some speed
improvement when using templates. However...
I wrote a basic list container (using templates), and a list container
(using virtual derived classes). I also tried...
|
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.
For the full tree it's easy. We walk up the parents getting the name of each
node and put a / between each so we end up with /node1/node2 or
node1/node2/@attr1
|
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.
The 'Document' configNode contains the flwg:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |