I have some XML that I\'d like to transform into HTML using a number of XSL files. These XSL files are all related through xsl:import and xsl:include statements, and all require
I had the same problem just now. My solution was to propagate the includes directly into the XML. This code was tested under Chrome, Firefox and IE 10,9,8 and 7.
function propegateIncludes(dname,xml, isExplorer) {
var preTag = isExplorer ? "xsl:" : "";
var TAG_STYLESHEET = preTag + "stylesheet", TAG_INCLUDE = preTag
+ "include", TAG_TEMPLATE = preTag + "template";
var stylesheets = xml.getElementsByTagName(TAG_STYLESHEET);
if (stylesheets.length == 0) {
return;
}
var includes = xml.getElementsByTagName(TAG_INCLUDE);
if (includes.length == 0) {
return;
}
var stylesheet = stylesheets[0];
var path = dname.substring(0, dname.lastIndexOf('/'));
for ( var i = 0; i < includes.length; i++) {
var args = includes[i].attributes;
var includeXml = null;
for ( var a = 0; a < args.length; a++) {
if (args[a].nodeName == "href") {
includeXml = loadXMLDoc(path + "/" + args[a].nodeValue);
break;
}
}
stylesheet.removeChild(includes[i]);
if (includeXml != null) {
var templates = includeXml.getElementsByTagName(TAG_TEMPLATE);
for (var t = 0; t < templates.length; ++t) {
stylesheet.appendChild(templates[t].cloneNode(true));
}
}
}
}