Partager via


Transforming XML Data Islands in an HTML Page

 

When building an XSLT solution that uses Internet Explorer, you might want to use data islands as a convenient way to access XML data from an HTML page. Because XSLT is itself an XML grammar, data islands can be used to load style sheets as well. The simple-islands.htm example in XSLT Sample: Breakfast Menu uses two data islands to load both the source XML data and the XSLT style sheet. The transformNode method is used on these two data islands to generate HTML code that can then be inserted into the page.

When the simple-islands.htm page, including the data islands, is completely loaded, the onload event fires and the transformNode method is executed on the XML source data. The result of this call is XML text, which in this example is well-formed HTML text. You can feed this text directly into the <xslTarget> element as in xslTarget.innerHTML = source.transformNode(style.XMLDocument)

The object returned from a data island is a DHTML DOM object (in this case it is the DHTML object associated with the <XML> element), not an XML DOM object. The style.XMLDocument property ensures that a style object is passed to the transformNode method as an XML DOM object.

There is no need to write source.XMLDocument.transformNode(style.XMLDocument), because transformNode is an XML DOM method, not a DHTML method. When an XML DOM method is called on a DHTML object corresponding to the XML data island element, the script engine automatically resolves it to the XML DOM Document node. In general, the XMLDocument property is not required if another DOM property or method is being applied.

You can also write source.XMLDocument.transformNode(style.documentElement) and apply the style sheet to the document element instead of the root. However, the style sheet must reflect this. For example, the document element must be handled by a rule other than the root template xsl:template match="/", which will not be invoked unless the style sheet is executed against the document root. It is recommended that you process your style sheets off the document root so that they will also work for directly browsing XML.

For more information, see Deploying XSLT in Internet Explorer.

Example

For an example of an HTML page with XML Data Islands, see simple-islands.htm in XSLT Sample: Breakfast Menu.

See Also

XML Data Islands
Performing Error Handling with XSLT
Getting Transformation Results as a DOM Document