Project

Profile

Help

Saxon 10.3 and classpath: scheme

Added by Vladimir Nesterovsky about 3 years ago

I have found that "classpath:" scheme does not work as I expected. I'm not sure whether it is by design or a bug, so I just put it here:

Consider a folder structure:

  c:\temp\child\a.xslt
  c:\temp\b.xslt
  c:\temp\input.xml

a.xslt:

<xsl:stylesheet version="3.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xsl:include href="../b.xslt"/>
</xsl:stylesheet>

b.xslt:

<xsl:stylesheet version="3.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
</xsl:stylesheet>

input.xml - is any xml

When I run a.xslt using file system it works:

java -cp Saxon-HE-10.3.jar net.sf.saxon.Transform -s:c:\temp\input.xml -xsl:C:\temp\child\a.xslt -o:c:\temp\output.xml

When I try to use "classpath:" scheme it does not work:

java -cp Saxon-HE-10.3.jar;C:\temp net.sf.saxon.Transform -s:c:\temp\input.xml -xsl:classpath:child/a.xslt -o:c:\temp\output.xml

with error:

Error on line 4 column 34 of a.xslt:
  XTSE0165  I/O error reported by XML parser processing classpath:../b.xslt: unknown
  protocol: classpath. Caused by java.net.MalformedURLException: unknown protocol: classpath
I/O error reported by XML parser processing classpath:../b.xslt: unknown protocol: classpath

Replies (5)

Please register to reply

RE: Saxon 10.3 and classpath: scheme - Added by Michael Kay about 3 years ago

Saxon's standard/default URIResolver recognises the classpath scheme, but the XML parser presumably doesn't. If you want the XML parser to handle classpath URLs you'll need to customise it with your own EntityResolver.

RE: Saxon 10.3 and classpath: scheme - Added by Vladimir Nesterovsky about 3 years ago

I know but why StandardURIResolver decides to resolve "../b.xslt" against "classpath:child/a.xslt" to "classpath:../b.xslt". After such resolution no StandardURIResolver itself nor xml parser is able to proceed.

RE: Saxon 10.3 and classpath: scheme - Added by Vladimir Nesterovsky about 3 years ago

More correctly it's ResolveURI.makeAbsolute() called from StandardURIResolver is doing:

            } else if (base.startsWith("classpath:")) {
                absoluteURI = new URI(relativeURI);
                if (!absoluteURI.isAbsolute()) {
                    absoluteURI = new URI("classpath:" + relativeURI);
                }

RE: Saxon 10.3 and classpath: scheme - Added by Michael Kay about 3 years ago

Saxon tries to handle classpath URIs wherever possible. But it can't force third-party code to handle them.

RE: Saxon 10.3 and classpath: scheme - Added by Vladimir Nesterovsky about 3 years ago

It's Saxon's attempt to resolve <xsl:include href="../b.xslt"/>, and it builds url "classpath:../b.xslt", which does not sound right. That strange uri it sends to third-party xml API. If StandardURIResolver could resolve it to "classpath:b.xslt" then it would work.

    (1-5/5)

    Please register to reply