[XML-SIG] 4Suite problems

Michael Hall ninti@ninti.com
Fri, 13 Dec 2002 13:57:53 +1100


Quoting Anders Bruun Olsen <anders@bruun-olsen.net>:

Warning: I am a relative newbie to Python, 4Suite and XSLT, I may easily have 
missed something obvious in your example, and you may be trying to do something 
I'm not even aware of. That said, however ...

Do you need to explicitly open the XML and XSL files? Normally, you would 
simply supply filepaths to the processor:

> def ProcessFile(input, output):

          stylesheet = "/path/to/somesheet.xsl"
>         xsltprocessor = Processor()
>         
>         xsltprocessor.appendStylesheetUri(stylesheet)
>         result = xsltprocessor.runUri(input)
>         if result:
>                 open(output, "w").write(result)

This works for me creating dynamically generating HTML web pages with a Python 
CGI script, except that I do this with the result:

if result:
    print "Content-type: text/html\n\n"
    print result



Sorry if I've misunderstood what you're trying to do.

Mick


> Hi,
> 
> I am not 100% sure that this is the right place to seek help - please
> direct me to the right place if I am off-topic.
> 
> I am trying to make an app that amongst other things applies an XSLT to
> an XML file to produce HTML. I have made the XSLT and the following
> code:
> 
> def ProcessFile(input, output):
>         XSLT = open("ujds.xslt", "r").read()
> 
>         XML = open(input, "r").read()
> 
>         xsltprocessor = Processor()
>         
>         transform = InputSource.DefaultFactory.fromString(XSLT)
>         document = InputSource.DefaultFactory.fromString(XML)
> 
>         xsltprocessor.appendStylesheet(transform)
>         result = xsltprocessor.run(document)
>         if result:
>                 open(output, "w").write(result)
> 
> Whenever I run the app and try to run the ProcessFile function I get
> this crash:
> 
> ./print.py:64: RuntimeWarning: Creation of InputSource without an URI
>   transform = InputSource.DefaultFactory.fromString(XSLT)
> /usr/lib/python2.2/site-packages/Ft/Xml/InputSource.py:147: RuntimeWarning:
> Creation of InputSource without an URI
>   return apply(self.fromStream, (stream,uri)+v_args, kw_args)
> ./print.py:65: RuntimeWarning: Creation of InputSource without an URI
>   source = InputSource.DefaultFactory.fromString(XML)
> Traceback (most recent call last):
>   File "./print.py", line 119, in ?
>     app = IndeksApp(0)
>   File "/usr/lib/python2.2/site-packages/wxPython/wx.py", line 1581, in
> __init__
>     _wxStart(self.OnInit)
>   File "./print.py", line 108, in OnInit
>     self.mainframe = MainFrame(NULL, -1, "UJDS Indeks")
>   File "./print.py", line 89, in __init__
>     if ProcessFile(inputfile, outputfile):
>   File "./print.py", line 68, in ProcessFile
>     result = xsltprocessor.run(document)
>   File "/usr/lib/python2.2/site-packages/Ft/Xml/Xslt/Processor.py", line 150,
> in run
>     raise XsltException(Error.SOURCE_PARSE_ERROR, iSrc.uri or '<Python
> string>', e)
> Ft.Xml.Xslt.XsltException: Source document
> (urn:uuid:303010c-b08-503-20b-f050b09309): Invalid base URI:
> urn:uuid:303010c-b08-503-20b-f050b09309
> 
> What am I doing wrong here?
> 
> -- 
> Anders
> -----BEGIN GEEK CODE BLOCK-----
> Version: 3.12
> GCS/O d--@ s:+ a-- C++ $UL+++ P++ L+++ E- W+ N(+) o K? w O- M-- V
> PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b+ DI+++ D+ G e- h !r y?
> ------END GEEK CODE BLOCK------
> PGPKey: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8BFECB41
> 
> _______________________________________________
> XML-SIG maillist  -  XML-SIG@python.org
> http://mail.python.org/mailman/listinfo/xml-sig
> 



----------------------------------------------------
MICHAEL HALL                 Web Development Officer
Batchelor Institute of Indigenous Tertiary Education
W: mick.hall@nt.gov.au                (08) 8951 8352
H: ninti@ninti.com                    (08) 8953 1442
----------------------------------------------------