6

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. )

Pops
  • 30,199
  • 37
  • 136
  • 151
Mikhail
  • 1,583
  • 5
  • 22
  • 34

2 Answers2

4

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()

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • 3
    Correct but general answer, missing explanation: the relative uri for `xsl:import` declaration will be resolved with stylesheet URI as Base URI. Whether the XSLT proccesor can handle that URI scheme or it has right privileges, it's another issue. From : http://www.w3.org/TR/xslt#import *The `xsl:import` element has an `href` attribute whose value is a URI reference identifying the stylesheet to be imported. A relative URI is resolved relative to the base URI of the `xsl:import` element* –  Jan 17 '11 at 18:52
3

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

Community
  • 1
  • 1
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147