tags:

views:

621

answers:

4

Hello,

I have a simple XSL file which looks like:

<?xml version='1.0'?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 

<xsl:import href="html/docbook.xsl"/> 

</xsl:stylesheet>

I have an XSL file which lies in a folder on the disk (not on the web). It's path relative to my XSL file (above) is:

..\..\..\Dependencies\XSL\xsl\htmlhelp\htmlhelp.xsl

<xsl:import href="..\..\..\Dependencies\XSL\xsl\htmlhelp\htmlhelp.xsl"/>

or

<xsl:import href="../../../Dependencies/XSL/xsl/htmlhelp/htmlhelp.xsl"/>

doesn't seem to be working (I get - can not find file - errors from xslproc tool.)

What is the proper way of writing relative paths in the XSL:import ?

Thanks in advance,

Paul

A: 

To be sure, the front-slash characters are the ones to be used, i.e.

<xsl:import href="..\..\..\Dependencies\XSL\xsl\htmlhelp\htmlhelp.xsl"/>

is positively incorrect, not need to pursue this track.

The issue may be that the "Base URI" (as defined in RFC 2396) is not what we expect. Although I believe the standard is explicit about rules pertaining to the determination of the base URI, there is some ambiguity with various xslt processors.

If you are w/ XSLT 2.0 you may try to use fn:base-uri() to see that this URI is indeed the one you'd expect.

mjv
A: 

It would be helpful if you described how you are attempting to run your stylesheets.

One common issue with relative paths for include/import in Java: When you load an XSLT as a StreamSource and do not set a SystemID, the processor doesn't know "where" the XSLT is and cannot resolve relative paths.

http://www.onjava.com/pub/a/onjava/excerpt/java_xslt_ch5/index.html?page=5

By providing a system identifier as a parameter to the StreamSource, you are telling the XSLT processor where to look for commonFooter.xslt. Without this parameter, you may encounter an error when the processor cannot resolve this URI. The simple fix is to call the setSystemId( ) method as follows:

// construct a Source that reads from an InputStream
Source mySrc = new StreamSource(anInputStream);
// specify a system ID (a String) so the 
// Source can resolve relative URLs
// that are encountered in XSLT stylesheets
mySrc.setSystemId(aSystemId);

The other thing to double check is that your relative paths are indeed correct. Browse to where your XSLT is in the command prompt and cd to that relative path to see if it finds the file.

Mads Hansen
+1  A: 

I tested a simple stylesheet import using your relative path and xsltproc. It worked for me - so your relative path must be wrong.

fpmurphy
A: 

Use xsltproc --stringparam baseURI file:///path/to/your/stylesheet.xsl -o result.xml stylesheet.xsl input.xml

xixxix