Problem with libxml2/libxlst

Discussion in 'Python' started by CinnamonDonkey, Jun 10, 2010.

  1. Hi All,

    I could not find a dedicated libxml2/libxlst group so I thought I
    would see if anyone here could help.

    I have a system which captures the stdout from various sources and
    writes it into a generic xml file. This file then needs to be
    transformed to get the correct html format for rendering in a
    webserver.

    I am using the following code to perform the translation:

    styledoc = libxml2.parseFile('stdout.xsl')
    style = libxslt.parseStylesheetDoc(styledoc)

    doc = libxml2.parseFile('stdout.xml')
    result = style.applyStylesheet(doc, None)

    style.saveResultToFilename('stdout.html'), result, 0)

    style.freeStylesheet()
    doc.freeDoc()
    result.freeDoc()

    Given the following stdout.xml sample:

    <report>
    <stdout>some app spew...</stdout>
    <stdout>laa laaa laa...</stdout>
    <stdout>something interesting &lt;badthinghappening&gt;</stdout>
    </report>

    It seems that the resultant 'stdout.html' file shows the final stdout
    message translated too:

    <stdout>something interesting <badthinghappening></stdout>

    which of course results in a badly formed file with a missing tag :(

    How do I get libxml2/libxlst to not touch the '&lt;' and '&gt;'

    Cheers
    -Shaun
    CinnamonDonkey, Jun 10, 2010
    #1
    1. Advertising

  2. My mistake! *doh*

    I had an 'disable-output-escape="YES"' when it should have been "NO".

    -Shaun

    On 10 June, 10:17, CinnamonDonkey <>
    wrote:
    > Hi All,
    >
    > I could not find a dedicated libxml2/libxlst group so I thought I
    > would see if anyone here could help.
    >
    > I have a system which captures the stdout from various sources and
    > writes it into a generic xml file. This file then needs to be
    > transformed to get the correct html format for rendering in a
    > webserver.
    >
    > I am using the following code to perform the translation:
    >
    >   styledoc = libxml2.parseFile('stdout.xsl')
    >   style = libxslt.parseStylesheetDoc(styledoc)
    >
    >   doc = libxml2.parseFile('stdout.xml')
    >   result = style.applyStylesheet(doc, None)
    >
    >   style.saveResultToFilename('stdout.html'), result, 0)
    >
    >   style.freeStylesheet()
    >   doc.freeDoc()
    >   result.freeDoc()
    >
    > Given the following stdout.xml sample:
    >
    > <report>
    >   <stdout>some app spew...</stdout>
    >   <stdout>laa laaa laa...</stdout>
    >   <stdout>something interesting &lt;badthinghappening&gt;</stdout>
    > </report>
    >
    > It seems that the resultant 'stdout.html' file shows the final stdout
    > message translated too:
    >
    >   <stdout>something interesting <badthinghappening></stdout>
    >
    > which of course results in a badly formed file with a missing tag :(
    >
    > How do I get libxml2/libxlst to not touch the '&lt;' and '&gt;'
    >
    > Cheers
    > -Shaun
    CinnamonDonkey, Jun 10, 2010
    #2
    1. Advertising

  3. On 6/10/10 7:47 AM, CinnamonDonkey wrote:
    > My mistake! *doh*
    >
    > I had an 'disable-output-escape="YES"' when it should have been "NO".
    >
    > -Shaun
    >


    Eeeeven though you figured out your problem: have you checked out lxml?
    Its extremely capable and ISTM much easier to use then whatever direct
    wrapper you seem to be using.

    Check out: http://codespeak.net/lxml/xpathxslt.html#xslt

    --

    Stephen Hansen
    ... me+list/python (AT) ixokai (DOT) io


    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.10 (Darwin)
    Comment: Public key available at: http://killnine.net/shansen.pub

    iQEcBAEBAgAGBQJMEQcqAAoJEKcbwptVWx/lYxQIALFdMLIgsTwc+7+kz0v386lO
    5SOKnI+1y15gtMr1XfCacTeK/ZNn/Rm5hKUMd80YzD5LN2ft33cuhC+29DHyfCIS
    se/DOxDKYmJM/c1S5HJtMTwZDSAp+T08i2C7AuIJyKIYnIslN7KoGPcazOQe/V3L
    674uvpUdMKqHz2eo3Glo1flg5O4gnWy+/gGvJ7r2aUo1WoZ0p35VCrVgi/D0x/fR
    ouDJvWA8oALa6PwmJN6vw8469BWW4aQbEjxKBbkxCKyazyYskQQxY13XIa1VYQ0H
    vDUYwfafBhbBv/+YnJkVM6Kx96CE0HKXWaRburFeu6ZB4UgTvtaXCv84aUrXE4c=
    =q1TR
    -----END PGP SIGNATURE-----
    Stephen Hansen, Jun 10, 2010
    #3
    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. Alain Ketterlin

    libxml2/libxslt crash

    Alain Ketterlin, Feb 26, 2004, in forum: XML
    Replies:
    0
    Views:
    472
    Alain Ketterlin
    Feb 26, 2004
  2. Replies:
    1
    Views:
    533
    Patrick TJ McPhee
    Mar 2, 2004
  3. Replies:
    0
    Views:
    446
  4. Rene Olsthoorn

    py2exe: problem including libxml2

    Rene Olsthoorn, Dec 4, 2003, in forum: Python
    Replies:
    6
    Views:
    408
    Rene Olsthoorn
    Dec 17, 2003
  5. corley

    decimal symbol problem (using libxml2)

    corley, Jul 5, 2006, in forum: C Programming
    Replies:
    2
    Views:
    407
    Keith Thompson
    Jul 5, 2006
Loading...

Share This Page