[Zope] trying to implement server side xsl transform

Thomas Bennett bennetttm at appstate.edu
Wed Oct 24 17:01:35 EDT 2007


Zope Version 	(Zope 2.10.3-final, python 2.4.3, linux2) 
using zeo storage

I am trying to implement a server side XSL Transform with the 
tools I have installed.   I have 4suite, libxml2,  and  libxsl.   The 
all of the files are dtml documents.

Listing 1 below works on the command line and writes an html 
file named 'foo' to the file system. So I added a def, a parameter 
to receive, and indent Listing 1 appropriately to run as an External 
Method.  I also found, from this list in September 2006, an almost 
identical External Method using parseDoc instead of parseFile, 
and SaveToString instead of SaveToFile, see Listing 2 and the 
traceback that follows it.

  All combinations and attempts to use an External Method result in 
either parseDoc or parseFile failing.  Also, the Zope server will not 
respond to WEB clients for as long as it is trying to process the 
External Method and Apache times out in about 100 seconds  with a 
Proxy error and I usually have to restart the Zope server to get 
access back to it through a WEB client although ps doesn't show
any unusual processor or memory usage.

  I have tried using Listing 1 and then read the file back in to return 
the html text but still get the same result, parse failed.

The test page, a dtml document, making the call only contains:

<dtml-call "C_xml2html('<dtml-var 0418rice.xml>')">
or 
<dtml-call expr="C_xml2html('<dtml-var 0418rice.xml>')">


Thanks for any help,

Thomas




Listing 1----  command line python script that works
********************
import libxml2
import libxslt

myxml="http://www.library.appstate.edu/appcoll/ead2002/0418rice.xml"
styledoc = libxml2.parseFile("http://www.library.appstate.edu/appcoll/ead2002/styles/eadbase.xsl")
style=libxslt.parseStylesheetDoc(styledoc)
doc=libxml2.parseFile(myxml)
result=style.applyStylesheet(doc, None)
style.saveResultToFilename("foo",result,0)
style.freeStylesheet()
doc.freeDoc
result.freeDoc()


Listing 2 ---- External Method python script
**********************
import libxml2
import libxslt

stylestring = file("/var/zope/Extensions/eadbase.xsl").read()

def xml2html(xmlfile):

  styledoc = libxml2.parseDoc(stylestring)
  style=libxslt.parseStylesheetDoc(styledoc)
  doc=libxml2.parseDoc(xmlfile)
  result=style.applyStylesheet(doc, None)
  html=style.saveResultToString(result)
  style.freeStylesheet()
  doc.freeDoc
  result.freeDoc()
  return html


Traceback from the call using Listing 2

2007-10-24T16:29:56 ERROR Zope.SiteErrorLog http://www.library.appstate.edu/appcoll/ead2002/0000_xmlxsltest.html
Traceback (innermost last):
  Module ZPublisher.Publish, line 119, in publish
  Module ZPublisher.mapply, line 88, in mapply
  Module ZPublisher.Publish, line 42, in call_object
  Module OFS.DTMLMethod, line 144, in __call__
   - <DTMLMethod at /appcoll/ead2002/0000_xmlxsltest.html>
   - URL: http://www.library.appstate.edu/appcoll/ead2002/0000_xmlxsltest.html/manage_main
   - Physical Path: /appcoll/ead2002/0000_xmlxsltest.html
  Module DocumentTemplate.DT_String, line 476, in __call__
  Module DocumentTemplate.DT_Util, line 196, in eval
   - __traceback_info__: C_xml2html
  Module <string>, line 1, in <expression>
  Module Products.ExternalMethod.ExternalMethod, line 231, in __call__
   - __traceback_info__: (('<dtml-var 0418rice.xml>',), {}, None)
  Module /var/zope/Extensions/xmlxsltests.py, line 11, in xml2html
  Module libxml2, line 1224, in parseDoc
parserError: xmlParseDoc() failed



-- 
====================================================================
Thomas McMillan Grant Bennett		Appalachian State University
Operations & Systems Analyst		P O Box 32026
University Library				Boone, North Carolina 28608
(828) 262 6587

They say a picture is worth a thousand words.  As videos could be 25 pictures per second and might last several minutes, how many words is that? 
- Linux Journal, July 2007

Library Systems Help Desk: http://www.library.appstate.edu/help/
====================================================================


More information about the Zope mailing list