Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSL import causing FileNotFoundException in web application

Tags:

java

xml

xslt

I have a simple web application under websphere5. Under appDir\WEB-INF\classes\ I have these files:

  • main.xslt
  • templates.xslt

main.xslt contains the instruction

<xsl:import href="templates.xsl" />

but the application fails when main.xslt is used in Java code. How should I specify the path to imported XSL files if they all are in the same folder (WEB-INF\classes\)?

Text of exception:

java.io.FileNotFoundException: d:\Program Files\WebSphere\AppServer1\templates.xsl (The system cannot find the file specified. )

like image 399
Mikhail Avatar asked Jan 17 '11 18:01

Mikhail


2 Answers

You need to provide a custom uri-resolver to process the includes. In a web application, there's no guarantee that a filesystem is accessible, as you could be running out of a WAR file. Take a look at the javax.xml.transform.URIResolver interface and Transformer.setURIResolver()

like image 132
Jim Garrison Avatar answered Sep 22 '22 17:09

Jim Garrison


Depending on how you loaded the main.xsl, you may need to set the SystemID property, so that it can resolve the relative path.

like image 26
Mads Hansen Avatar answered Sep 21 '22 17:09

Mads Hansen