Codesample for xml/xslt transforming

H

Harry George

Thomas Guetttler said:
Am Tue, 09 Sep 2003 14:45:54 +0200 schrieb Axel Straschil:


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?
 
A

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 ...

Thanks,
AXEL.
 
T

Thomas Guetttler

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
 
J

Jeremy Jones

* Axel Straschil ([email protected]) wrote:

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.DefaultFactory.fromString(xsl_data, "uri"))
result = processor.run(Ft.Xml.InputSource.DefaultFactory.fromString(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
 
A

Axel Straschil

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.
 
J

John J. Lee

Hello!


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)

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
 
A

Axel Straschil

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 shit, 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".
 
M

Max M

Axel said:
Im programming with Zope/Python/PostgreSQL to produce dynamic content
for Webpages. I realy was fu**ed up of the whole PHP shit, 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
 
A

Axel Straschil

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 address removed)
Public Key: http://www.kosnet.com/pgp-public-key.txt
Keyserver: http://www.keyserver.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top