Chapter 10 - To HTML and Beyond! | |
XSLT For Dummies | |
by Richard Wagner | |
Hungry Minds 2002 |
Under most circumstances, you link together an XML document with an XSLT stylesheet by specifying the .xml and .xsl files when you call the XSLT processor. However, XML offers a way to direct connect an XML file with an XSLT stylesheet by using the xml-stylesheet processing instruction. The instructions basic syntax is: <?xml-stylesheet href="lyon.xsl" type="text/xsl"?> Remember xml-stylesheet is an XML processing instruction, not an XSLT element. When declared in an XML file, this instruction tells the processing engine to apply the specified stylesheet to the contents of the source XML. The instruction has two parameters:
Therefore, if I want to apply the quotes.xsl stylesheet to the quotes.xml document when the XML file is processed , I add the xsl-stylesheet processing instruction to the top of the file (note that most of the quote elements are removed in this abbreviated Listing 10-2). Listing 10-2: quoteslink.xml <?xml version="1.0"?> <?xml-stylesheet href="quotes.xsl" type="text/xsl"?> <filmquotes> <quote> <spokenby>Buzz Lightyear</spokenby> <source>Toy Story</source> <text>To infinity, and beyond!</text> </quote> <quote> <spokenby>Sam</spokenby> <source>Bennie and Joon</source> <text>It seems to me that, aside from being a little mentally ill, she's pretty normal.</text> </quote> <quote> <spokenby>Sabrina</spokenby> <source>Sabrina</source> <text>More isn't always better, Linus. Sometimes it's just more.</text> </quote> </filmquotes> Warning You must place the xsl-stylesheet processing instruction at the top of the XML document, before the document element is declared.
|