Linking XSLT to a Source XML Document
Instructing the XSLT processor to do a transformation is often referred to as linking an XSLT style sheet to an XML document. There are two ways to do this.
- Embed an XSLT style sheet inside the source XML document. In the Hello, World! example, the
<?xml-stylesheet type="text/xsl" href="hello.xsl"?>
processing instruction does this. When you run the source XML file from within Internet Explorer, the transformation is applied automatically. However, you have little control as to which XSLT processor to invoke, unless you use MSXML 4.0 or later on Windows XP computers. If you are not running Windows XP, the processor used is likely to be the one shipped with Internet Explorer—that is, MSXML 2.0. - Explicitly call the
transformNode
ortransformNodeToObject
method on the Document Object Model (DOM) of the source XML document. Do this from a script, or from another programming language that allows you to create the DOM for the source XML document and the XSLT style sheet. This method allows you full control over which version of MSXML you want to use. Currently, this is the only way to use MSXML 4.0 or later, unless you use MSXML 4.0 or later with Windows XP.
For more information about using MSXML 5.0 with Windows XP, see MSXML 5.0 and Windows XP.
For an example of linking to a source document via script, see Initiate XSLT in a Script