[Zope] trying to implement server side xsl transform

Thomas Bennett bennetttm at appstate.edu
Thu Oct 25 10:14:25 EDT 2007


Kees,

  The files are dtml documents and use the xsl file correctly 
when viewed in IE usually.  When viewed in Opera the only 
result is "XSLT processing failed!" on the browser page.  In 
Firefox the page doesn't show any images and some text is 
not shown.  These files relate to old records often used by 
genealogists and from my experience they are usually elderly 
and using old browsers but even a recent Firefox in linux I 
just tried doesn't show some text or images.

  Someone else is creating these files and I know there are 
syntax problems with some pages but I don't have time to tutor 
this author in XML, I just give comments and suggestions 
occasionally such as use xmllint.  I've only been asked to 
implement server side transform on our Zope server.

  4Suite does the transform by applying the xsl style sheet to the 
xml file and returns formatted html  text suitable for all browsers.  
Ft in site-packages comes from 4suite, see 4suite.org for more info.

There are examples for other xsl tools at 
http://uche.ogbuji.net/tech/akara/nodes/2003-01-01/python-xslt

The solution I ended up with even after the one in the reply to 
myself lets you add /ead2xml on the end of the url of the xml 
page(eg. htttp://www.mysite.mydomain/xmlfile.xml/ead2xml)
This implies that my External Method is called ead2xml and
it is.  Below is ead2xml.py that does this.  All of the pages use
the same xsl file so it is hard coded in the script.


from Products.PythonScripts.standard import html_quote
from ZPublisher import HTTPResponse
from Ft.Xml.Xslt import Transform
import string

def ft_transform(self):

  request=self.REQUEST
  response=self.REQUEST.RESPONSE

  xmlfile="%s"%request.URL1[(len(request.URL2))+1:len(request.URL0)]
  mysource="http://www.library.appstate.edu/appcoll/ead2002/%s"%xmlfile
  result = Transform(mysource, "http://www.library.appstate.edu/appcoll/ead2002/styles/eadbase.xsl")
  return result



Thomas


On Thursday 25 October 2007 03:33, Kees de Brabander wrote:
> I don't fully understand what your are doing, though I am interested in a
> xsl transformations in Zope.
> Your dtml must fail, however, because you can't use a dtml-tag within a
> python expression. I would upload the xml document as a dtml-document and
> call it just by its name.
> By the way: what role does 4suite play in your process?
> If you have a working solution, would you be willing to share it?
> cb
>
> -----Oorspronkelijk bericht-----
> Van: zope-bounces at zope.org [mailto:zope-bounces at zope.org] Namens Thomas
> Bennett
> Verzonden: woensdag 24 oktober 2007 23:02
> Aan: zope at zope.org
> Onderwerp: [Zope] trying to implement server side xsl transform
>
> 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/e
>a dbase.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/
> ====================================================================
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )

-- 
====================================================================
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