[XML-SIG] 4Suite problems

Uche Ogbuji uche.ogbuji@fourthought.com
Fri, 13 Dec 2002 08:41:59 -0700

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

I always strongly suggest that you still use URIs here.  For example

transform = InputSource.DefaultFactory.fromString(XSLT, "ujds.xslt")

This avoids errors if you try to do something later that performs resolution 
against a relative URI.

Note that you can just write:

        xsltprocessor = Processor()
        transform = InputSource.DefaultFactory.fromUri("ujds.xslt")
        document = InputSource.DefaultFactory.fromUri(input)

Which will eliminate the error and will have the additional advantage of being 
a tad faster.

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

This exception does mask the real problem, unfortunately, but I'm about 90% 
sure that you're doing something (XSLT document() call, XInclude resolution, 
xsl:import or something) that tries to resolve a relative URI.  The problem is 
that you haven't provided a base URI, so 4Suite rightly complains (though in 
an obfuscated way: I'll look into that).

I pointed to the likely solution above.  You may also want to browse my 
article on 4Suite:


Which gives a fuller example and some discussion.  A fuller discussion on 
4Suite's pickiness about URIs is in the following:


Uche Ogbuji                                    Fourthought, Inc.
http://uche.ogbuji.net    http://4Suite.org    http://fourthought.com
Tour of 4Suite - http://www.xml.com/pub/a/2002/10/16/py-xml.html
Proper XML Output in Python - http://www.xml.com/pub/a/2002/11/13/py-xml.html
RSS for Python - http://www-106.ibm.com/developerworks/webservices/library/ws-p
Debug XSLT on the fly - http://www-106.ibm.com/developerworks/xml/library/x-deb