Re: [xsl] <xsl:include> and Oracle java classes

Subject: Re: [xsl] <xsl:include> and Oracle java classes
From: "Steve Muench" <Steve.Muench@xxxxxxxxxx>
Date: Thu, 1 Mar 2001 14:36:20 -0800
| I'm writing a Java app that selects data from our Oracle database, formats
| it into XML then uses the Oracle 'XSLStylesheet' and 'XSLProcessor' classes
| to load a stylesheet and transform the XML. 
| Unfortunately it fails on the first <xsl:include> - I assume because the
| main stylesheet is loaded as an InputStream, and the included stylesheets
| are still files on the disk.
| Is there a way for the Oracle classes to load stylesheets referenced by
| <xsl:include>?

Sure. Load the stylesheet from a resource URL instead of
as an InputStream. The input stream approach works when
the stylesheet has no relative stylesheets it needs to
read, but by using a resource URL, all of the relative
references are handled for you.

Here a sample. Assumes the "Sample.xsl" stylesheet and
the "SampleHelper.xsl" stylesheet which the former
includes via <xsl:include> are at the the same level
of directory hierarchy in your CLASSPATH as the current class.

import oracle.xml.parser.v2.*;
public class TransformExample {
  public static void main( String[] arg ) throws Throwable {
    DOMParser theParser = new DOMParser();
    XMLDocument source = theParser.getDocument();
    // Resource "Sample.xsl" does <xsl:include href="SampleHelper.xsl"/>
    URL url = TransformExample.class.getResource("Sample.xsl");
    XSLStylesheet transform = new XSLStylesheet(url,url);
    XSLProcessor proc = new XSLProcessor();

Steve Muench, Lead XML Evangelist & Consulting Product Manager
BC4J & XSQL Servlet Development Teams, Oracle Rep to XSL WG
Author "Building Oracle XML Applications", O'Reilly

 XSL-List info and archive:

Current Thread