views:

315

answers:

1

I am using Javascript to load XML and transform it with XSLT. Everything works until I try to use <xsl:include>. Is it possible to include files this way?

Here is the relevant XSLT code.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
...
<xsl:include href="another_xslt.xsl"/>
</xsl:stylesheet>

And here is the javascript code:

var xmlRequest = new XMLHttpRequest();
xmlRequest.open("GET", "data.xml", false);
xmlRequest.send(null);

var xsltRequest = new XMLHttpRequest();
xsltRequest.open("GET", "https://hostname.com/directory/xslt/transform.xsl", false);
xsltRequest.send(null);

var xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsltRequest.responseXML);
return xsltProcessor.transformToDocument(xmlRequest.responseXML);

I am using Firefox 3.5 and the script fails on the xsltProcessor.importStylesheet line without any error messages.

Update:

Tamper Data shows a request for another_xslt.xsl but in the parent directory so it is getting a 404.

All the xslt files are in https://hostname.edu/directory/xslt/ but Firefox is requesting http://hostname.edu/directory/another%5Fxslt.xsl instead. Why would it be requesting the file from the parent directory and without the https? The html file is in /directory/admin/edit

Using the full URL fixes the problem, but I need it to work on the server, so I would prefer to use the relative path like it is now.

+2  A: 

It is possible to xsl-include with importStylesheet() so that shouldn't be the problem.

I do not really have the answer but perhaps some pointers to verify:

Do you have an infinite inclusion recursion where file x includes y which in turn includes x?

Make sure the xsl:include is not followed by an xsl:import.

If you use something like Tamper Data do you see FireFox requesting 'another_xslt.xsl' ?

Long shot guess: I never seen an xsl:include that wasnt defined straight under xsl:stylesheet before any xsl:template declarations perhaps moving this xsl:include declaration to the top might help (keeping in mind it xsl:import should go first).

Martijn Laarman
Excellent assumptions +1
Thiyagaraj
Thanks for the suggestions. Tamper Data shows the request but it is coming from the parent directory. I will update the question with the details.
mcrumley
I see you accepted my answer did you end up resolving your issue ?
Martijn Laarman
I changed the href to a full URL based on your suggestion to try Tamper Data. I would still prefer to use a relative URL (see the update)
mcrumley