Re: [Zope] trying to implement server side xsl transform

2007-10-25 Thread Thomas Bennett
I started trying a solution with libxml2/libxslt which did work in python on 
the command line but failed through the WEB  While browsing the WEB I came
across lxml and didn't spend much time on it but now looking at it I think the 
tools from 4suite still involve less code although there may be some better 
features offered with lxml I have only skimmed the documentation pages.  With 
4suite the simplest case is :

from Ft.Xml.Xslt import Transform

result = Transform((xmlfile, xsltfile)

Although some examples show also importing TransformPath you will get messages 
with newer versions that TransformPath has been deprecated so it is not 
needed.


Thanks,  I am going to look some more at lxml.

Thomas

On Thursday 25 October 2007 08:53, Martijn Faassen wrote:
> Hello,
>
> Concerning xslt transformations, you might want to consider an easier
> API to use the XSLT infrastructure in libxml2/libxslt: lxml. See
> http://codespeak.net/lxml
>
> Regards,
>
> Martijn
> ___
> Zope maillist  -  Zope@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 AnalystP 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@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 )


Re: [Zope] trying to implement server side xsl transform

2007-10-25 Thread Thomas Bennett
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Thomas
> Bennett
> Verzonden: woensdag 24 oktober 2007 23:02
> Aan: zope@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:
>
> ')"> or  expr="C_xml2html('')">
>
>
> 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.

RE: [Zope] trying to implement server side xsl transform

2007-10-25 Thread Kees de Brabander
Interesting. Thanks. 
cb 

-Oorspronkelijk bericht-
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens
Martijn Faassen
Verzonden: donderdag 25 oktober 2007 14:53
Aan: Kees de Brabander
CC: [EMAIL PROTECTED]; zope@zope.org
Onderwerp: Re: [Zope] trying to implement server side xsl transform

Hello,

Concerning xslt transformations, you might want to consider an easier API to
use the XSLT infrastructure in libxml2/libxslt: lxml. See
http://codespeak.net/lxml

Regards,

Martijn



--
No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.503 / Virus Database: 269.15.10/1091 - Release Date: 24-10-2007
14:31


___
Zope maillist  -  Zope@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 )


Re: [Zope] trying to implement server side xsl transform

2007-10-25 Thread Martijn Faassen
Hello,

Concerning xslt transformations, you might want to consider an easier
API to use the XSLT infrastructure in libxml2/libxslt: lxml. See
http://codespeak.net/lxml

Regards,

Martijn
___
Zope maillist  -  Zope@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 )


Re: [Zope] trying to implement server side xsl transform

2007-10-25 Thread Thomas Bennett
On Wednesday 24 October 2007 23:35, Andreas Jung wrote:
> --On 24. Oktober 2007 17:01:35 -0400 Thomas Bennett
>
> <[EMAIL PROTECTED]> wrote:
> > 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.
>
> This it basically offtopic and unrelated to Zope. First get this fixed on
> the  Python level - then move your code to Zope.
>
I did mentioned above that "python myscript.py" did run on the command line 
but hung in Zope, or are you referring to something different by "Python 
level"?

> >   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.
>
> Keep in mind that Zope works by default with 4  worker threads. If they are
> blocked with long-running processes than other requests will be queued and
> their execution delayed until the next thread has finished this work.
>
> -aj
I had my threads set to 10 but have upped them to 16 to see if that will make 
a difference, thanks.  I've also upped the pool size because of several 
instances of 

2007-10-24T10:33:07 WARNING ZODB.DB DB.open() has 10 open connections with a 
pool_size of 7

in the event log.

Thanks,

Thomas


-- 

Thomas McMillan Grant Bennett   Appalachian State University
Operations & Systems AnalystP 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@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 )


RE: [Zope] trying to implement server side xsl transform

2007-10-25 Thread Kees de Brabander
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Thomas
Bennett
Verzonden: woensdag 24 oktober 2007 23:02
Aan: zope@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:

')"> or 


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/ea
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/_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__
   - 
   - URL:
http://www.library.appstate.edu/appcoll/ead2002/_xmlxsltest.html/manage_
main
   - Physical Path: /appcoll/ead2002/_xmlxsltest.html
  Module DocumentTemplate.DT_String, line 476, in __call__
  Module DocumentTemplate.DT_Util, line 196, in eval
   - __traceback_info__: C_xml2html
  Module , line 1, in 
  Module Products.ExternalMethod.ExternalMethod, line 231, in __call__
   - __traceback_info__: (('',), {}, 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 AnalystP 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@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 )



-- 
No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.503 / Virus Database: 269.15.10/1091 - Release Date: 24-10-2007
14:31


___
Zope maillist  - 

Re: [Zope] trying to implement server side xsl transform

2007-10-24 Thread Andreas Jung



--On 24. Oktober 2007 17:01:35 -0400 Thomas Bennett 
<[EMAIL PROTECTED]> wrote:



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.


This it basically offtopic and unrelated to Zope. First get this fixed on 
the  Python level - then move your code to Zope.




  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.


Keep in mind that Zope works by default with 4  worker threads. If they are 
blocked with long-running processes than other requests will be queued and

their execution delayed until the next thread has finished this work.

-aj



pgpMzWxtEiF5U.pgp
Description: PGP signature
___
Zope maillist  -  Zope@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 )