Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<SCRIPT type='text/javascript'>
function testXSL() {
try {
var req = new XMLHttpRequest();
req.open("GET", "empty.xsl", false);
req.send(null);
var xsl = req.responseXML;
if( !xsl ) {
alert("Unable to load xsl!");
return false;
}
alert(new XMLSerializer().serializeToString( xsl.documentElement ));
var xsl_processor = new XSLTProcessor();
xsl_processor.importStylesheet( xsl );
req.open("GET", "empty.xml", false);
req.send(null);
var xml = req.responseXML;
if( !xml ) {
alert("Unable to load xml!");
return false;
}
var result_doc = xsl_processor.transformToDocument( xml );
if( !result_doc ) {
alert("Unable to transform!");
return false;
}
alert(new XMLSerializer().serializeToString(result_doc.documentElement));
}
catch( e ) {
alert("XSLT error: "+e.message + "(" + e + ")");
return false;
}
}
//</SCRIPT>
</HEAD>
<BODY>
<input type="button" value="test XSL" onclick="testXSL();"/>
</BODY>
</HTML>
--- empty.xsl ---
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:import href="utility_template.xsl"/>
</xsl:stylesheet>
--- empty.xml ---
<root></root>
void XSLStyleSheet::loadChildSheets()
{
if (!document())
return;
xmlNodePtr stylesheetRoot = document()->children;
// Top level children may include other things such as DTD nodes, we ignore those.
while (stylesheetRoot && stylesheetRoot->type != XML_ELEMENT_NODE)
stylesheetRoot = stylesheetRoot->next;
if (m_embedded) {
// We have to locate (by ID) the appropriate embedded stylesheet element, so that we can walk the
// import/include list.
xmlAttrPtr idNode = xmlGetID(document(), (const xmlChar*)(href().utf8().data()));
if (!idNode)
return;
stylesheetRoot = idNode->parent;
} else {
// FIXME: Need to handle an external URI with a # in it. This is a pretty minor edge case, so we'll deal
// with it later.
}
if (stylesheetRoot) {
// Walk the children of the root element and look for import/include elements.
// Imports must occur first.
xmlNodePtr curr = stylesheetRoot->children;
while (curr) {
if (curr->type != XML_ELEMENT_NODE) {
curr = curr->next;
continue;
}
if (IS_XSLT_ELEM(curr) && IS_XSLT_NAME(curr, "import")) {
xmlChar* uriRef = xsltGetNsProp(curr, (const xmlChar*)"href", XSLT_NAMESPACE);
loadChildSheet(DeprecatedString::fromUtf8((const char*)uriRef));
xmlFree(uriRef);
} else
break;
curr = curr->next;
}
// Now handle includes.
while (curr) {
if (curr->type == XML_ELEMENT_NODE && IS_XSLT_ELEM(curr) && IS_XSLT_NAME(curr, "include")) {
xmlChar* uriRef = xsltGetNsProp(curr, (const xmlChar*)"href", XSLT_NAMESPACE);
loadChildSheet(DeprecatedString::fromUtf8((const char*)uriRef));
xmlFree(uriRef);
}
curr = curr->next;
}
}
}
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Quite a while ago I posted a fix for a similar issue for the Sarissa cross-browser XSLT library, which was related to relative paths and *.js files, where IE and other browsers interpreted the base path differently. If a path problem may be the cause of your issue, you can test that by applying an absolute path to see if that makes a difference.
-- Abel --