Codesample for xml/xslt transforming

Discussion in 'Python' started by Harry George, Sep 9, 2003.

  1. Harry George

    Harry George Guest

    "Thomas Guetttler" <> 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?


    --

    6-6M31 Knowledge Management
    Phone: (425) 342-5601
    Harry George, Sep 9, 2003
    #1
    1. Advertising

  2. 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.
    Axel Straschil, Sep 9, 2003
    #2
    1. Advertising

  3. 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
    Thomas Guetttler, Sep 9, 2003
    #3
  4. Harry George

    Jeremy Jones Guest

    * Axel Straschil () 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.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
    Jeremy Jones, Sep 9, 2003
    #4
  5. 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.
    Axel Straschil, Sep 9, 2003
    #5
  6. Harry George

    John J. Lee Guest

    (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
    John J. Lee, Sep 9, 2003
    #6
  7. 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".

    --
    Lg,
    Axel.
    Axel Straschil, Sep 9, 2003
    #7
  8. Harry George

    Max M Guest

    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 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
    Max M, Sep 10, 2003
    #8
  9. 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:
    Public Key: http://www.kosnet.com/pgp-public-key.txt
    Keyserver: http://www.keyserver.net
    Axel Straschil, Sep 10, 2003
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Adams
    Replies:
    1
    Views:
    706
    Arnaud Berger
    Mar 10, 2005
  2. Bernd Fuhrmann
    Replies:
    0
    Views:
    438
    Bernd Fuhrmann
    Feb 12, 2004
  3. Jody Greening
    Replies:
    5
    Views:
    679
    Jody Greening
    Jan 6, 2005
  4. Jody Greening
    Replies:
    0
    Views:
    338
    Jody Greening
    Jan 6, 2005
  5. Replies:
    2
    Views:
    463
    David Carlisle
    Feb 1, 2005
Loading...

Share This Page