1 Reply Latest reply on Sep 22, 2004 2:49 AM by oz_ko

    XSLT URIResolver Issues

    oz_ko

      Is anyone aware of URIResolver issues with included stylesheets?

      If no resolver is specified stylesheets that include other stylesheets default to the jboss bin directory which is not good so I've created a custom URIResolver to load up included stylesheets

      transformerFactory.setURIResolver(
       new URIResolver() {
       public Source resolve(String href,String base) {
       StreamSource ss = null;
       try {
       ss = new StreamSource(new StringReader(new String(
      org.apache.commons.io.IOUtils.toByteArray(
      Thread.currentThread()
      .getContextClassLoader()
      .getResourceAsStream("com/company/xsl/DateTemplate.xsl")))));
      
       } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
      
       return ss;
      
       }
       }
      );
      


      The stylesheet is loaded correctly so that is not the issue. The SteamSource is fine. ( I know the StreamSource definition is not the best - it's only there for testing). I've also tried:

      ss = new StreamSource(
      Thread.currentThread().getContextClassLoader()
      .getResourceAsStream("com/company/xsl/DateTemplate.xsl");
      


      However I get an exception:

      java.lang.NullPointerException
       at com.icl.saxon.style.XSLGeneralIncorporate.getIncludedStyleSheet(XSLGeneralIncorporate.java:104)
       at com.icl.saxon.style.XSLStyleSheet.spliceIncludes(XSLStyleSheet.java:421)
       at com.icl.saxon.style.XSLStyleSheet.preprocess(XSLStyleSheet.java:346)
       at com.icl.saxon.PreparedStyleSheet.setStyleSheetDocument(PreparedStyleSheet.java:176)
       at com.icl.saxon.PreparedStyleSheet.prepare(PreparedStyleSheet.java:133)
       at com.icl.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:127)
       at com.icl.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:79)
      


      Anyone come across this problem?

      config:
      jboss 3.2.5
      java 1.4.2_05
      winxp pro


      TIA
      Oz

        • 1. Re: XSLT URIResolver Issues
          oz_ko

          I've removed the offending saxon parser so I am now using the default xalan 2.6.0.

          HOWEVER, I'm still getting a null pointer exception:

          when:
          org.apache.xpath.SourceTreeManager.resolveURI

          calls my resolver passing in the required href stylesheet I resolve it with my custom resover. If it is not my styleshee I use the default URIResolver. The default URIResolver then throws a NPE.

          Any ideas ANYONE?

          Thanks
          Oz