Linking an XSLT Stylesheet with an XML Document

 
xslt for dummies
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:

  • href specifies the URI of the XSLT stylesheet.

  • type tells what kind of file the stylesheet is (or its MIME type). XSLT stylesheets have the type of text/xsl .

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
start example
 <?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> 
end example
 

 Warning   You must place the xsl-stylesheet processing instruction at the top of the XML document, before the document element is declared.

  
 
 
2000-2002    Feedback


XSLT For Dummies
XSLT for Dummies
ISBN: 0764536516
EAN: 2147483647
Year: 2002
Pages: 148

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net