Share via


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.

  1. 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, with this approach, you have little control as to which XSLT processor to invoke. The exact version of MSXML will depend somewhat on which version of Internet Explorer you have in use. For more information about MSXML and Internet Explorer, see MSXML with Internet Explorer.

  2. Explicitly call the method used to initiate XSLT transformation from code.

    XSLT transformations can also be linked to a source document programmatically. IN general, you will load the XML document object instance and then apply the transform using the appropriate method.

    For MSXML implementations, the methods to use here would be either the transformNode or transformNodeToObject methods. These can be used from script contained within a Web page. For an example of this approach, see Initiate XSLT in a Script.