Re: [xml-bindings]Composing documents using Python and libxslt
- From: Daniel Veillard <veillard redhat com>
- To: Jørgen Frøjk Kjærsgaard <jfk metation com>
- Cc: xml-bindings gnome org
- Subject: Re: [xml-bindings]Composing documents using Python and libxslt
- Date: Wed, 10 Apr 2002 15:38:36 -0400
On Thu, Apr 04, 2002 at 04:12:25PM +0200, Jørgen Frøjk Kjærsgaard wrote:
> Hi,
>
> I need to be able to compose XML documents from Python-generated
> sub-ducuments. To do this I register a Python extension function using
> xsltRegisterExtModuleFunction().
>
> However, I am unable to create an include function, which can be used in my
> XML documents. Two things go wrong for some reason:
Well you're on the bleeding edge :-)
> 1) When the argument to the include function itself is an XPath expression,
> it is passed to my Python program as a list of C objects (case 1,2 in the
> test document below), whereas it is passed as a string if I write a string
> directly (case 3).
Yes to return a node set you would have to return a list of libxml2
nodes.
> 2) When I attempt to apply-templates to the result of my external Python
> function, I get no output.
Hum, no idea ATM. I would have to work on debugging this.
> I have previously succeeded in doing this using Sablotron, however Sablotron
> seems to have some serious memory management bugs, which makes it crash all
> the time when running under apache and mod_python. libxml/libxslt seems to be
> a much stronger toolcase...
>
> ** The function:
>
> def _include(self, ctx, str):
> print "- CALLING INCLUDE(%s:%s)" % (str[0], type(str))
> return "<pre>python pre</pre>"
>
> ** The stylesheet:
>
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:mtr="http://metation.com/mtr"
> exclude-result-prefixes="mtr"
> >
>
> <xsl:output method="html" indent="yes"/>
>
> <xsl:template match="test">
> <html>
> test tag start
> <xsl:apply-templates/>
> test tag slut
> </html>
> </xsl:template>
>
>
> <xsl:template match="include">
> INCLUDE:<xsl:apply-templates select="mtr:include(@resource)"/>:INCLUDE
> </xsl:template>
>
>
> <xsl:template match="include-raw">
> INCLUDE-RAW:<xsl:value-of select="mtr:include(@resource)"/>:INCLUDE-RAW
> </xsl:template>
>
> <xsl:template match="incl-direct">
> INCL-DIRECT:<xsl:value-of select="mtr:include('DIRECT')"/>:INCL-DIRECT
> </xsl:template>
>
> <xsl:template match="pre">
> <PRE>
> <xsl:value-of select="."/>
> </PRE>
> </xsl:template>
>
> </xsl:stylesheet>
>
> ** The test document:
>
> <test>
> <include resource="TEST"/> <!-- case 1 -->
> <include-raw resource="RAWTEST"/> <!-- case 2 -->
> <incl-direct resource="DIRTEST"/> <!-- case 3 -->
> <pre>direkte pre</pre>
> </test>
>
> ** The result:
>
> - CALLING INCLUDE(<PyCObject object at 0x81edcf0>:<type 'list'>)
> - CALLING INCLUDE(<PyCObject object at 0x81edd18>:<type 'list'>)
> - CALLING INCLUDE(D:<type 'string'>)
> <html>
> test tag start
>
>
> INCLUDE::INCLUDE
>
>
> INCLUDE-RAW:<pre>python pre</pre>:INCLUDE-RAW
>
>
> INCL-DIRECT:<pre>python pre</pre>:INCL-DIRECT
>
> <PRE>direkte pre</PRE>
>
> test tag slut
> </html>
>
>
> Thanks, jfk
I can't garantee I will be able to work on this really soon, would
you mind posting this on the bugzilla for libxslt so I don't forget your
problem ?
http://xmlsoft.org/XSLT/bugs.html
TIA,
Daniel
--
Daniel Veillard | Red Hat Network https://rhn.redhat.com/
veillard redhat com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]