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
 
M

Mike Schilling

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.

More likely, it's just using JRun's default directory .
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.

Specify a URI resolver (Transformer.setURIResolver()) This should be called
with the relative URI, which you can then translate to a Source using
whatever logic is necessary. For instance, you can now find glcodes.xml as
a Java resource instead of an external file, which may make packaging your
application simpler.

You'll probably want to start with getURIResolver(), so you can chain to any
existing resolver for URLs you don't want to process yourself.
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top