This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: <xsl:include> and Oracle java classes
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: Re: [xsl] <xsl:include> and Oracle java classes
- From: "Steve Muench" <Steve dot Muench at oracle dot com>
- Date: Thu, 1 Mar 2001 14:36:20 -0800
- References: <C02FE75A852BD211820A00A0C944C9AC01AEF615@syn1mx2>
- Reply-To: xsl-list at lists dot mulberrytech dot com
| 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.*;
import java.net.URL;
public class TransformExample {
public static void main( String[] arg ) throws Throwable {
DOMParser theParser = new DOMParser();
theParser.parse(new java.io.StringReader("<x/>"));
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();
proc.processXSL(transform,source,System.out);
}
}
______________________________________________________________
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
http://www.oreilly.com/catalog/orxmlapp/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list