Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Codesample for xml/xslt transforming

Reply
Thread Tools

Codesample for xml/xslt transforming

 
 
Harry George
Guest
Posts: n/a
 
      09-09-2003
"Thomas Guetttler" <(E-Mail Removed)> writes:

> Am Tue, 09 Sep 2003 14:45:54 +0200 schrieb Axel Straschil:
>
> > Hello!
> >
> > Im fouling around with xml/xslt and zope.
> > Now, im seraching for a simple codesample or link
> > for a simple xslt-tranformation in python and libxml
> > or 4Suite.
> > I've test.xml, test.xsl or two vars with the code
> > and wan't to transform it.
> > Google just helped me for C ...

>
> 4suite contains examples and tests. You could see how they work.
>
> BTW, I used to waste a lot of time with xslt.
> I think you are most of the time quicker with SAX for
> parsing XML and "print" to create XML.
>
> thomas
>


I came to the same conclusion. XSLT's declarative paradigm runs out
of gas just when the problem gets interesting. E.g., when the
topology of the incoming data does not match that of the outgoing
data. From there on in, you are tangled in xml-based procedural code.

What I'd like to see is a good pattern or even code to help set up the
SAX and print code given a neutral representation of the incoming and
outgoing formats. The neutral reps should be generated from SQL,
XSchema, RELAX/NG, csv headers, etc. Anything like that out there?


--
http://www.velocityreviews.com/forums/(E-Mail Removed)
6-6M31 Knowledge Management
Phone: (425) 342-5601
 
Reply With Quote
 
 
 
 
Axel Straschil
Guest
Posts: n/a
 
      09-09-2003
Hello!

Im fouling around with xml/xslt and zope.
Now, im seraching for a simple codesample or link
for a simple xslt-tranformation in python and libxml
or 4Suite.
I've test.xml, test.xsl or two vars with the code
and wan't to transform it.
Google just helped me for C ...

Thanks,
AXEL.
 
Reply With Quote
 
 
 
 
Thomas Guetttler
Guest
Posts: n/a
 
      09-09-2003
Am Tue, 09 Sep 2003 14:45:54 +0200 schrieb Axel Straschil:

> Hello!
>
> Im fouling around with xml/xslt and zope.
> Now, im seraching for a simple codesample or link
> for a simple xslt-tranformation in python and libxml
> or 4Suite.
> I've test.xml, test.xsl or two vars with the code
> and wan't to transform it.
> Google just helped me for C ...


4suite contains examples and tests. You could see how they work.

BTW, I used to waste a lot of time with xslt.
I think you are most of the time quicker with SAX for
parsing XML and "print" to create XML.

thomas

 
Reply With Quote
 
Jeremy Jones
Guest
Posts: n/a
 
      09-09-2003
* Axel Straschil ((E-Mail Removed)) wrote:

<snip>

> I've test.xml, test.xsl or two vars with the code
> and wan't to transform it.
> Google just helped me for C ...



This code used to work (kinda ugly, though - sorry):


from Ft.Xml.Xslt.Processor import Processor
import Ft.Xml.InputSource
##I was working with a DOM object here
xml_data = dom.toxml()
processor = Processor()
f = open("rmkr.xsl",'r')
xsl_data = f.read()
f.close()
processor.appendStylesheet(Ft.Xml.InputSource.Defa ultFactory.fromString(xsl_data, "uri"))
result = processor.run(Ft.Xml.InputSource.DefaultFactory.fr omString(str(xml_data), "uri"))
processor.reset()
result_html = os.path.join(result_dir, "%s.html" % outfile_prefix)
htmlfile = open(result_html, "w")
htmlfile.write(result)
htmlfile.close()

I haven't tested it recently to see if it still works. It worked with FT under Python 2.1.


Jeremy Jones

 
Reply With Quote
 
Axel Straschil
Guest
Posts: n/a
 
      09-09-2003
Hello!

> BTW, I used to waste a lot of time with xslt.


Jep, hard work for eight lines:
from Ft.Lib.Uri import OsPathToUri
from Ft.Xml import InputSource
from Ft.Xml.Xslt.Processor import Processor
STY = InputSource.DefaultFactory.fromUri('test.xsl')
SRC = InputSource.DefaultFactory.fromUri('test.xml')
proc = Processor()
proc.appendStylesheet(STY)
print proc.run(SRC)

> I think you are most of the time quicker with SAX for
> parsing XML and "print" to create XML.


It's for an CMS-System. I think XML and XLST is a good thing
if programmer and webdesigner have to work together, and you
realy want to seperate the content from the design
(Even when I think god had a bad day when he craeted
webdesigner .

Lg,
AXEL.
 
Reply With Quote
 
John J. Lee
Guest
Posts: n/a
 
      09-09-2003
(E-Mail Removed) (Axel Straschil) writes:

> Hello!
>
> > BTW, I used to waste a lot of time with xslt.

>
> Jep, hard work for eight lines:
> from Ft.Lib.Uri import OsPathToUri
> from Ft.Xml import InputSource
> from Ft.Xml.Xslt.Processor import Processor
> STY = InputSource.DefaultFactory.fromUri('test.xsl')
> SRC = InputSource.DefaultFactory.fromUri('test.xml')
> proc = Processor()
> proc.appendStylesheet(STY)
> print proc.run(SRC)


That looks like Python code to me, Axel, not XSLT <wink>. It's
writing the XSLT that's the pain, not interpreting it (though that can
certainly be 'arbitrarily difficult' -- in the words of K&R, IIRC --
if the XSLT implementors have hidden the command-line utility well
enough).

The utility of XSLT is that everybody can agree to hate it equally
<0.3 wink>. If the world were saner, we'd all agree to *like* Python
equally, but there you go.

(actually, I don't hate it in itself -- just the way people view it as
being particularly useful, which seems unjustified)


> > I think you are most of the time quicker with SAX for
> > parsing XML and "print" to create XML.

>
> It's for an CMS-System. I think XML and XLST is a good thing
> if programmer and webdesigner have to work together, and you
> realy want to seperate the content from the design
> (Even when I think god had a bad day when he craeted
> webdesigner .


XML is good because it's an widely-understood, easy-to-read,
not-to-complicated, *non*-loathesome standard that gets the job done.
XSLT... well, it's a standard. And it has an 'X' in the name, of
course, which is the killer feature <wink>.


John
 
Reply With Quote
 
Axel Straschil
Guest
Posts: n/a
 
      09-09-2003
Hello!

> That looks like Python code to me, Axel, not XSLT <wink>. It's


Yeah, I've ordered it, I've got it!

> writing the XSLT that's the pain, not interpreting it (though that can


Mhh, XSLT is not very usefull for programming, but I don't think that it
hurts so much.

> XML is good because it's an widely-understood, easy-to-read,
> not-to-complicated, *non*-loathesome standard that gets the job done.
> XSLT... well, it's a standard. And it has an 'X' in the name, of
> course, which is the killer feature <wink>.


I agree with you that all the X* things are an marketing killer feature.
Let mit tell you the little story how I came to the whole X-Biest:
Im programming with Zope/Python/PostgreSQL to produce dynamic content
for Webpages. I realy was fu**ed up of the whole PHP ****, where content
and source was sticked together. Zope makes thinks better, but not
perfekt. I didn't want to switch to XSLT, becouse of speed. But I didn't
found anything better if you want to bring the content in an blackbox
to the webdesigner. I was also booring always digging around in the
sources when the design of an site changed.
So, with XSLT, if design is changing, I don't care. I even don't care
about XSLT, becouse I should be the designers work to change it. I see
XLST as an "scripting language".

--
Lg,
Axel.
 
Reply With Quote
 
Max M
Guest
Posts: n/a
 
      09-10-2003
Axel Straschil wrote:

> Im programming with Zope/Python/PostgreSQL to produce dynamic content
> for Webpages. I realy was fu**ed up of the whole PHP ****, where content
> and source was sticked together. Zope makes thinks better, but not
> perfekt.



Have you used the page templates in Zope? They really are a thing of beauty.


regards Max M

 
Reply With Quote
 
Axel Straschil
Guest
Posts: n/a
 
      09-10-2003
Hallo!

> Have you used the page templates in Zope? They really are a thing of beauty.


Yes, zope's page templates are good. I've two site's where I'm using them.
My point of interest is:
If your are coding the html-output of a website with dtml/pt in Zope or
php, you've got the problem that:
- The webdesigner has to dig in your source
- You must code your program like the html-code is comming, not the data
With the last point, I mean that that a html-page ist codet top down, and
so dtml/pt are parest from the top to the bottom.
Imagine I'm fetching an Article from via the network from an remote
server, the Article has an caption and an content. I want to show the
caption in the title-tag of the header, and the article somewhere nested
in the body. With dtml/pt, I must either access the remote article server
twice, or make a funny variable definition construktion. Not very nice!

If my output ist not html, it's xml, a can make an data-orientated output,
not design orientated. Maybe dtml/pt is used to produce that xml-code, who
cares. The webdesigner is starting at the OUTPUT of the xml-code, he is
just seeing that (dynamic modifing) xml-code, he's never digging my
source.

So, the last thing ist to convert that data-orientated xml to designers
xhtml. It's like taking pieces of data from the xml and placing them
on the webpage. No funking programming, yust templaging. I think for that,
XSLT ist a good thing. But I'm just starting, maybe, in one or two weeks,
I'll shredder all that X-Files, or maybe I'll love them

--
Lg,
Axel.
__________________________________________________ __
/_\ Tel: +43(699) 145 09 210
/|_ \xel Fax: +43(699) 445 09 210
_|traschil eMail: (E-Mail Removed)
Public Key: http://www.kosnet.com/pgp-public-key.txt
Keyserver: http://www.keyserver.net


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.Net control for uploading, cropping and transforming graphics file FrankV ASP .Net 0 11-08-2005 03:28 AM
Transforming xml using xslt into a string variable? Ken Adams Java 1 03-10-2005 04:13 PM
Design Query - Transforming XML Roger Varley Java 0 02-03-2005 02:17 PM
Transforming XML with XSL to String Krista Lemieux ASP .Net 1 08-10-2004 02:41 PM
Transforming xml with server controls with xsl dwhitford ASP .Net 0 05-14-2004 02:44 PM



Advertisments