xsl document function - java SimpleTransform cannot find file

M

marty.gagnon

I have a xsl file that references a xml file using the document()
function.
I'm having trouble specifying the URI in the document() function of a
xls stylesheet.

I'm using java to transform the stylesheet, and when it evaluates the
document() function, it cannot find the specified file.

This is how I reference the xml file I'm having trouble with
<xsl:value-of select="document('glcodes.xml',//)/glcodes/code"/>

I'm using JRun as the web server and I get the following error

SystemId Unknown; Line 1; Column -1; Can not load requested doc:
C:\JRun4\bin\glcodes.xml (The system cannot find the file specified)

I may understand what is going on. The document() function loads the
file (in this case "glcodes.xml") relative to the xml file used when
the xsl file is transformed. So in my below code, the "xmlSource" is
loaded into memory and used. I guess since JRun is doing the
transformation in memory the relative path is starting at the location
where the Xalan processor has this file in memory which would be
...\JRun4\bin. The question is, how do I modify the URI in the
document() fuction so it's relative to where the xml file is loaded
from.

javax.xml.transform.Transformer transformer =
tFactory.newTransformer(xslSS);
ByteArrayInputStream baais = new
ByteArrayInputStream(xmlByteArray);
BufferedInputStream biis = new BufferedInputStream(baais);
StreamSource xmlSource = new StreamSource(biis);
transformer.transform(xmlSource, result);

Thanks
Marty
 
J

Joseph Kesselman

I may understand what is going on. The document() function loads the
file (in this case "glcodes.xml") relative to the xml file used when
the xsl file is transformed.

No, it's relative to the URI at execution time. But you constructed a
StreamSource from a BufferedInputStream, which has no obvious base URI
for the StreamSource to use as this starting point. In this situation,
you have to explicitly assert a base URI on the StreamSource before
passing it to the transform() operation. There's a method call for that
purpose.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top