The xsl:output element is used to define the format of the output created by the stylesheet. This is accomplished by setting one or more of ten optional attributes. The most important of these ten attributes is the method attribute which dictates if the type of output is HTML, text, or XML. The type of output, in turn, dictates which of the other nine attributes can be applied to the output.
The following table defines which attributes can optionally be set for each of the three types of output. A dash signifies that the attribute cannot effect the output.
Attribute | HTML | Text | XML |
---|---|---|---|
cdata-section-elements | - | - | YES |
doctype-public | YES | - | YES |
doctype-system | YES | - | YES |
encoding | YES | YES | YES |
indent | YES | - | YES |
media-type | YES | YES | YES |
omit-xml-declaration | - | - | YES |
standalone | - | - | YES |
version | YES | - | YES |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" version="4.0" />
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="devguru_staff/programmer">
<div>
NAME: <xsl:value-of select="name" />
<br />
DOB: <xsl:value-of select="dob" />
<br />
AGE: <xsl:value-of select="age" />
<br />
ADDRESS: <xsl:value-of select="address" />
<br />
PHONE: <xsl:value-of select="phone" />
<hr />
</div>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
In this example, we declare our output to be in HTML. (By default, the occurrence of the <html> tag in the code signifies to the Microsoft XSLT processor we are using that the output is to be in HTML.)