Crane Softwrights Ltd.

Resource Library - Debugging Stylesheets Using Microsoft IE5 XSL Processing

This has turned out to be a frequently asked question on the XSL maillist XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list so now this resource can be refered to as a summary of a methodology to debug stylesheets being developed for the Microsoft IE5 XSL engine. This is useful because the menu function View/Source in IE5 shows the XML source, not the HTML resulting from the transformation described by the XSL stylesheet.

The page below is excerpted from the XSLT training materials that can be obtained through the http://www.CraneSoftwrights.com/training/ page:

  • Practical Transformation Using XSLT and XPath
    XSL Transformations and the XML Path Language
    (Ninth Edition - ISBN 1-894049-06-3 - 2001-01-19)
 Crane Logo

CRANE
SOFTWRIGHTS
LTD.

BOX 266,
KARS, ONTARIO
CANADA K0A-2E0

+1 (613) 489-0999 (Voice)
+1 (613) 489-0995 (Fax)

The XSL engine in Internet Explorer 5 (see http://www.netcrucible.com/xslt/msxml-faq.htm for very helpful information regarding XSLT in IE5) can be invoked using a tool from Microsoft named the Windows Scripting Host. The script described below will load an XML document and an XSL stylesheet and emit the results of transforming the XML using the XSL.

By directing the emitted results to a file, the behaviour of the XSL engine on a given stylesheet is revealed, thus helping with the debugging of the stylesheet logic.

This environment is also useful for creating a collection of static HTML pages that will reflect the same result as running IE5 from a browser, thus simultaneously supporting IE5 and non-IE5 browsers with the identical presentation.

Section D-5: Microsoft Internet Explorer 5 (Page 368)


The MSXML processor can be used from the MSDOS command line to emit transformations using the system character set: The following is a simple script adapted from one posted to the XSL mail list. This invokes the MSXML processor after loading two Document Object Model (DOM) objects. In the following code, the processor uses the system character encoding when emitting the result tree (for example, the Latin1 character set on Western European Windows systems and the Shift-JIS character set on Japanese Windows systems).
//File:  msxml.js - 2000-04-20 16:30
//Info:  http://www.CraneSoftwrights.com/links/msxml.htm
//Args:  input-file style-file output-file
var xml  = WScript.CreateObject("Microsoft.XMLDOM");          //input
xml.validateOnParse=false;
xml.load(WScript.Arguments(0));
var xsl  = WScript.CreateObject("Microsoft.XMLDOM");          //style
xsl.validateOnParse=false;
xsl.load(WScript.Arguments(1));
var out = WScript.CreateObject("Scripting.FileSystemObject"); //output
var replace = true; var unicode = false; //output file properties
var hdl = out.CreateTextFile( WScript.Arguments(2), replace, unicode )
hdl.write( xml.transformNode( xsl.documentElement ));
//eof
The following is a sample invocation batch file (the cscript program is from the Windows Scripting Host utility):
@echo off
REM msxml.bat
REM check arguments: %1=source XML, %2=script MSXML, %3=result HTML
cscript //nologo ..\prog\msxml.js %1 %2 %3
REM post-process results
The following is a sample invocation:
X:\samp>..\prog\msxml hello.xml hello.xsl hello.mshtm
X:\samp>type hello.mshtm
<b><i><u>Hello world.</u></i></b>
X:\samp>
In the following code, the processor uses the UTF-8 character encoding when emitting the result tree (adapted with kind permission from Makoto Murata)
//File:  msxmlu8.js - 2000-04-20 16:30
//Info:  http://www.CraneSoftwrights.com/links/msxml.htm
//Args:  input-file style-file output-file
var xml  = WScript.CreateObject("Microsoft.XMLDOM");          //input
xml.validateOnParse=false;
xml.load(WScript.Arguments(0));
var xsl  = WScript.CreateObject("Microsoft.XMLDOM");          //style
xsl.validateOnParse=false;
xsl.load(WScript.Arguments(1));
var out = WScript.CreateObject("Microsoft.XMLDOM");           //output
out.async = false;
out.validateOnParse=false;
xml.transformNodeToObject( xsl, out );
out.save(WScript.Arguments(2));
//eof
The two above processes are distinguished by the target of the transformation process:

If anyone has comments on this document, they are welcome to send them to debugmsxml@CraneSoftwrights.com.

$Date: 2001/01/20 10:27:03 $(UTC)