272 11 The XML Transformation Language
the elements. Of course, it is better to view XML documents using an XML
editor.
Although XSLT is usually pretty good about guessing your intentions, it is
not always obvious whether your output file is supposed to be an XML file
or it just has some of the XML features. To tell XSLT exactly what you intend,
include one of the following at the beginning of your XSLT program:
- For XML output files:
<xsl:output method="xml" media-type="text/xml"/>
- For HTML output files:
<xsl:output method="html" media-type="text/html"/>
- For output files that are neither XML nor HTML:
<xsl:output method="text" omit-xml-declaration="yes"/>
If your output file is not an XML document, then you may want to exer-
cise more precise control over the output formatting by using thexsl:text
element. Consider these two templates:
<xsl:template match="Protein">
Protein information:
<xsl:apply-templates select="@*|node()"/>
</xsl:template>
<xsl:template match="Protein">
<xsl:text>Protein information:</xsl:text>
<xsl:apply-templates select="@*|node()"/>
</xsl:template>
The first template would produce generous amounts of space before and af-
ter theProtein information:text in the output file, while the second
would write nothing more than just theProtein information:text.
Since XSLT is designed to produce XML documents, it automatically chang-
es the left angle bracket from<to<. XSLT also automatically changes