Applying Style Sheets Dynamically

Inserting an <?xml-stylesheet> directive in an XML document is not the only way to associate a style sheet with that document. As you’ll see in Chapters 9, 10, and 11, you can also use programming techniques to attach the style sheet on the fly. The basic technique is to use the Document Object Model’s transformNode() method. The method takes the name of a style sheet as a parameter and assigns it to the document object you’ve specified.

As an example, you could take the XML document in Listing 2.1, remove the <?xml-stylesheet> directive, and place the document on a Web server. You would also place the XSLT style sheet containing the HTML transformation in the same directory on the server. Then, you could use ...

Get Special Edition Using XSLT now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.