A lot of the examples in this chapter have converted XML into HTML, and you might have wondered how an XSLT processor knows to omit the <?xml?> declaration from the beginning of such output documents. It turns out that there's a special rule here: If the document node of the output document is <HTML> , the XSLT processor knows that the output document type is HTML and writes the document accordingly . In fact, you can specify three types of output documents:
You can set the output method by setting the <xsl:output> element's method attribute to "xml" , "html" , or "text" . For example, if you want to create an HTML document, even though the root element is not <HTML> , you can use this <xsl:output> element: <xsl:output method = "html"/> Another useful attribute of <xsl:output> is the indent attribute, which allows the XSLT processor (but does not force it) to insert whitespace to indent the output. Here's how you can use this attribute: <xsl:output indent = "yes"/> Here are some <xsl:output> attributes you can use to create or modify XML declarations:
Another useful attribute of <xsl:output> is media-type , which lets you specify the MIME type of the output document. Here's an example: <xsl:output media-type="text/xml"/> You can also use the <xsl:output> doctype-system and doctype-public attributes to specify an external DTD. For example, this <xsl:output> element <xsl:output doctype-system = "planets.dtd"/> produces a <!DOCTYPE> element in the output document like this: <!DOCTYPE PLANETS SYSTEM "planets.dtd"> As you can see, there's a tremendous amount going on in XSL transformations. In fact, there's more that we can cover here. For plenty of additional details, take a look at New Riders' Inside XSLT (it's a great bookwell, that's what I think, anyway, because I wrote it), the W3C XSLT specification at www.w3.org/TR/xslt, and the XPath specification at www.w3.org/TR/xpath. There's more to XSL. Besides XSL transformations, XSL includes a whole formatting language. I'm going to take a look at that next . |