18.10. Referencing XSLT stylesheets There is a W3C Recommendation that specifies how XML documents should refer to their stylesheets. Here is the relevant text: Model (xml-ss) 18-1. The xml-stylesheet processing instruction The xml-stylesheet processing instruction is allowed anywhere in the prolog of an XML document. The processing instruction can have pseudo-attributes href (required), type (required), title (optional), media (optional), charset (optional). These are called pseudo-attributes because, although they use attribute syntax, they do not describe properties of an element. The only real syntactic difference between pseudo-attributes and attributes is that you must use pseudo-attributes in the order they are defined. You can use attributes in any order. The most important pseudo-attributes for this processing instruction are href, which supplies a URI for the stylesheet, and type, which says whether the stylesheet is in XSLT, DSSSL, CSS, or some other stylesheet language. Example 18-27 is a sample stylesheet processing instruction (PI). Example 18-27. Stylesheet PI <?xml-stylesheet href="http://www.xmlbooks.com/memo.xsl" type="text/xsl"?> You can provide multiple PIs to allow for different output media or stylesheet language support. You could, for example, have different stylesheets for print (with footnotes and page breaks), online (with clickable links), television (large text and easy scroll controls) and voice (read aloud using inflection to render emphasis). In such cases, you would want to specify a media pseudo-attribute and possibly a title that the browser might use when offering a list of stylesheet choices. Example 18-28 demonstrates this. Example 18-28. Alternative stylesheets <?xml-stylesheet rel=alternate href="mystyle1.xsl" title="Fancy" media="print" type="text/xsl"?> <?xml-stylesheet rel=alternate href="mystyle2.css" title="Simple" media="online" type="text/css"?> <?xml-stylesheet rel=alternate href="mystyle2.aur" title="Aural" media="voice" type="text/aural"?> |