Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

xsl document() function - java SimpleTransform cannot find file

Thread view: 
marty.gagnon@imagenow.com - 28 Nov 2006 21:00 GMT
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
Mike  Schilling - 29 Nov 2006 02:19 GMT
>I have a xsl file that references a xml file using the document()
> function.
[quoted text clipped - 20 lines]
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.