Reputation: 5700
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">
...
<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_xslt.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.
Upvotes: 0
Views: 1301
Reputation: 13536
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).
Upvotes: 2