The following example adds error handling to qsalesregion.html. The lines added for error handling are in bold.
HTML File (qsalesregionwerrchk.html)
<HTML>
<HEAD>
<TITLE>Quarterly Sales, by Region</TITLE>
<SCRIPT language='JScript'>
<!--
function transformIt() {
// Associate the result tree object with any element(s) whose
// id attribute is "transformedXML."
var objResTree = document.all['transformedXML'];
// Declare two new MSXML DOMDocument objects.
var objSrcTree = new ActiveXObject('MSXML2.DOMDocument.5.0');
var objXSLT = new ActiveXObject('MSXML2.DOMDocument.5.0');
objXSLT.validateOnParse = true;
// Load the two DOMDocuments with the XML document and the
// XSLT style sheet.
objSrcTree.load('region.xml');
objXSLT.load('region.xsl');
if (objXSLT.parseError.errorCode != 0)
{
var strErrMsg = "Problem Parsing Style Sheet:<br />"
+" Error #: " + objXSLT.parseError.errorCode + "<br />"
+" Description: " + objXSLT.parseError.reason + "<br />"
+" In file: " + objXSLT.parseError.url + "<br />"
+" Line #: " + objXSLT.parseError.line + "<br />"
+" Character # in line: "+objXSLT.parseError.linepos + "<br />"
+" Character # in file: "+objXSLT.parseError.filepos + "<br />"
+" Source line: " +objXSLT.parseError.srcText;
objResTree.innerHTML = strErrMsg;
return false;
}
// Use the transformNode method to apply the XSLT to the XML.
strResult = objSrcTree.transformNode(objXSLT);
// Assign the resulting string to the result tree object's
// innerHTML property.
objResTree.innerHTML = strResult;
return true;
}
-->
</SCRIPT>
<BODY onload='transformIt()'>
<DIV id='transformedXML'></DIV>
</BODY>
</HTML>