title: Resolving relative paths when loading XSLT files
body: <p>I need to do an XSL transformation using Apache FOP and I had code like this:</p>
  
  <pre><code>//Setup FOP
  Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
  //Setup Transformer
  Source xsltSrc = new StreamSource(new File(xslPath));
  Transformer transformer = tFactory.newTransformer(xsltSrc);
  
  //Make sure the XSL transformation's result is piped through to FOP
  Result res = new SAXResult(fop.getDefaultHandler());
  //Setup input
  Source src = new StreamSource(new File(xmlPath));
  //Start the transformation and rendering process
  transformer.transform(src, res);
  </code></pre>
  
  <p>where <code>xslPath</code> is the path where my XSLT file is stored.</p>
  
  <p>I have confirmed that it works when I have only one XSLT file, but in my project I have divided things into several XSLT files and joined them with the <code>&lt;xsl:import /&gt;</code> tag. With this configuration, I get a NullPointerException because it doesn't understand all the information stored in XSLT because it's distributed over different files.</p>
  
  <p>I wonder if there's any way to load all these files in the <code>Source xsltSrc</code> variable so all the XSL information is available.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I've changed the code based on the answer given by Mads Hansen, but it still doesn't work. I have to include the XSLT slt files in the classpath, so I load the XSLT file with ClassLoader. I've checked that the URL has the correct path when executing <code>url.toExternalForm()</code>. This is my new piece of code:</p>
  
  <pre><code>ClassLoader cl = this.getClass().getClassLoader();
  String systemID = "resources/xslt/myfile.xslt";
  InputStream in = cl.getResourceAsStream(systemID);
  URL url = cl.getResource(systemID);
  Source source = new StreamSource(in);
  source.setSystemId(url.toExternalForm());
  transformer = tFactory.newTransformer(source);
  </code></pre>
  
  <p>It finds and loads <code>myfile.xslt</code> but it still doesn't resolve the relative paths to the other XSLT files.</p>
  
  <p>What am I doing wrong?</p>