[XML-SIG] 4Suite problems

Anders Bruun Olsen anders@bruun-olsen.net
Fri, 13 Dec 2002 17:02:01 +0100

On Fri, Dec 13, 2002 at 08:41:59AM -0700, Uche Ogbuji wrote:
> > 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.

Thanks, it works now!

I have one more thing though - As I already have the XML file parsed to
a DOM instance, it would be a nice thing if I could use that DOM
instance instead of reading the whole XML file again from disk. I have
tried this approach:

def ProcessFile(dom, input, output):

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

        result = xsltprocessor.runNode(dom, input)
        if result:
                open(output, "w").write(result)

Which results in a file with this line only:

<?xml version='1.0' encoding='UTF-8'?>

I am trying to output as HTML, which now works nicely through the other
way. How can I (if possible/feasible at all) just use the DOM instance
instead of loading the file?

> I pointed to the likely solution above.  You may also want to browse my 
> article on 4Suite:
> http://www.xml.com/pub/a/2002/10/16/py-xml.html
> Which gives a fuller example and some discussion.  A fuller discussion on 
> 4Suite's pickiness about URIs is in the following:
> http://uche.ogbuji.net/tech/akara/pyxml/domlettes/

Thanks, I'll look into those articles!

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?
PGPKey: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8BFECB41