Crane Softwrights Ltd.Resource Library - Debugging Stylesheets Using Microsoft IE5 XSL ProcessingThis 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:
|
CRANE
|
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)
//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 )); //eofThe 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 resultsThe 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)); //eofThe 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.