Project

Profile

Help

Stylesheet Source from ByteArrayOutputStream

Added by William You about 12 years ago

Hello.

Is it possible to feed Saxon a Stylesheet from an in memory source?

-- William


Replies (4)

Please register to reply

RE: Stylesheet Source from ByteArrayOutputStream - Added by O'Neil Delpratt about 12 years ago

Hi William,

You can use the ByteArrayInputStream instead. Saxon provides the s9api interface in Java. Please take a look at the following webpage with more details and examples:

http://www.saxonica.com/documentation/using-xsl/embedding/s9api-transformation.xml

Also below is an example of using the ByteArrayInputStream with the s9api interface in java:

        Processor proc = new Processor(true);

        DocumentBuilder builder = proc.newDocumentBuilder();

        XsltCompiler compiler = proc.newXsltCompiler();
        compiler.setXsltLanguageVersion("3.0");
        String stylesheet = " ... ";
        Source ss = null;
        try {
            byte[] byteArray = stylesheet.getBytes("UTF-8");
            ByteArrayInputStream inputStream = new ByteArrayInputStream(byteArray);
            ss = new StreamSource(inputStream);
        } catch (UnsupportedEncodingException e) {
            ...
        }
        try {
            XsltTransformer trans = compiler.compile(ss).load();
            trans.setSource(ss);
            Serializer serializer = new Serializer(System.out);
            trans.setDestination(serializer);
            trans.transform();
        } catch (SaxonApiException e) {
           ...
        }

Hope this helps

RE: Stylesheet Source from ByteArrayOutputStream - Added by William You about 12 years ago

Hi and thanks for the reply. Just what I needed.

I would like to point out that when I clicked your link to the documentation I got the following output :

This page contains the following errors:

error on line 2 at column 3: Char 0x0 out of allowed range
Below is a rendering of the page up to the first error

-- Thanks again.

William

RE: Stylesheet Source from ByteArrayOutputStream - Added by O'Neil Delpratt about 12 years ago

Thanks for the pointer. May I ask what environment are you using to view the link? I know on some mobile devices and in some browsers XSLT 1.0 does not work. If this is the case I suggest using our html version of the site: http://www.saxonica.com/html/documentation/using-xsl/embedding/s9api-transformation.html

RE: Stylesheet Source from ByteArrayOutputStream - Added by William You about 12 years ago

Hello O'Neil,

I'm using Debian Squeeze 6.0.5 on x64 and the browser is Iceweasel (aka Web Browser 2.30.6)

Hope this is of use to you.

-- William

    (1-4/4)

    Please register to reply