Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > lxml and xslt extensions

Reply
Thread Tools

lxml and xslt extensions

 
 
dasacc22
Guest
Posts: n/a
 
      04-04-2009
Hi,

Im not sure where else to ask this. But basically Im having trouble
figuring out how to successfully apply multiple extensions in a single
transformation. So for example if i have
<xsl:stylesheet .../>
<xsl:template...>
<my:tag/>
<my:tag/>
</xsl:template>
</xsl:stylesheet>

in my xsl and my xslt extension looks like

class TagExtension(etree.XSLTExtension):
def execute( ..., output_parent):
print 'executing tag_extension'
tag = etree.Element('p')
tag.text = 'Hello'
output_parent.append(tag)

well then the transformation works for the first tag and appends it to
the root of the created doc but all subsequent calls dont append
(maybe b/c output_parent is now somewhere else for return?). And to
clarify, I know that its the first call that completes and all
subsequent calls fail b/c i have a subsequent call that performs a
different transformation.

Thanks for any help or hints,
Daniel
 
Reply With Quote
 
 
 
 
dasacc22
Guest
Posts: n/a
 
      04-04-2009
On Apr 4, 11:31*am, dasacc22 <(E-Mail Removed)> wrote:
> Hi,
>
> Im not sure where else to ask this. But basically Im having trouble
> figuring out how to successfully apply multiple extensions in a single
> transformation. So for example if i have
> <xsl:stylesheet .../>
> <xsl:template...>
> <my:tag/>
> <my:tag/>
> </xsl:template>
> </xsl:stylesheet>
>
> in my xsl and my xslt extension looks like
>
> class TagExtension(etree.XSLTExtension):
> * def execute( ..., output_parent):
> * * print 'executing tag_extension'
> * * tag = etree.Element('p')
> * * tag.text = 'Hello'
> * * output_parent.append(tag)
>
> well then the transformation works for the first tag and appends it to
> the root of the created doc but all subsequent calls dont append
> (maybe b/c output_parent is now somewhere else for return?). And to
> clarify, I know that its the first call that completes and all
> subsequent calls fail b/c i have a subsequent call that performs a
> different transformation.
>
> Thanks for any help or hints,
> Daniel


Oh well I found the culprit, etree.tostring seems to cut it off after
the first transformation, simply doing a

$> print result

displays the entire document. To make use of the keyword options
xml_declaration, pretty_print, encoding, I tried using the .write
method of result to a StringIO but it produces the same clipped
result. Guess Ill have to edit the .docinfo attributes on the result
and return the string
 
Reply With Quote
 
 
 
 
Stefan Behnel
Guest
Posts: n/a
 
      04-04-2009
Hi,

dasacc22 wrote:
> On Apr 4, 11:31 am, dasacc22 wrote:
>> Im not sure where else to ask this.


The best place to ask is the lxml mailing list:

http://codespeak.net/mailman/listinfo/lxml-dev


>> But basically Im having trouble
>> figuring out how to successfully apply multiple extensions in a single
>> transformation. So for example if i have
>> <xsl:stylesheet .../>
>> <xsl:template...>
>> <my:tag/>
>> <my:tag/>
>> </xsl:template>
>> </xsl:stylesheet>
>>
>> in my xsl and my xslt extension looks like
>>
>> class TagExtension(etree.XSLTExtension):
>> def execute( ..., output_parent):
>> print 'executing tag_extension'
>> tag = etree.Element('p')
>> tag.text = 'Hello'
>> output_parent.append(tag)
>>
>> well then the transformation works for the first tag and appends it to
>> the root of the created doc but all subsequent calls dont append
>> (maybe b/c output_parent is now somewhere else for return?). And to
>> clarify, I know that its the first call that completes and all
>> subsequent calls fail b/c i have a subsequent call that performs a
>> different transformation.

>
> Oh well I found the culprit, etree.tostring seems to cut it off after
> the first transformation,


Not sure what you mean here. Could you post your question on the lxml
mailing list and add a runnable example that shows the behaviour?


> simply doing a
>
> $> print result
>
> displays the entire document. To make use of the keyword options
> xml_declaration, pretty_print, encoding, I tried using the .write
> method of result to a StringIO but it produces the same clipped
> result. Guess Ill have to edit the .docinfo attributes on the result
> and return the string


..docinfo is basically read-only. The result of the XSLT is serialised as
requested by the xslutput element in the stylesheet.

Stefan
 
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
etree/lxml/XSLT and dynamic stylesheet variables Adam Tauno Williams Python 0 01-20-2012 08:38 PM
lxml and identification of elements in source Laurent Pointal Python 1 09-20-2007 11:55 AM
lxml/ElementTree and .tail Chas Emerick Python 30 11-19-2006 04:34 PM
lxml and SimpleXMLWriter Srijit Kumar Bhadra Python 2 07-06-2006 05:49 PM
Unable to access extensions menu or add extensions (I've tried past suggestions) nospam@spam.com Firefox 8 12-01-2005 01:33 AM



Advertisments