xsl:stylesheet
xsl:transform
ELEMENT: xsl:output
<xsl:output
cdata-section-elements="namelist"
doctype-public="string"
doctype-system="string"
encoding="string"
indent="yes" | "no"
media-type="mimetype"
method="html" | "name" | "text" | "xml"
omit-xml-declaration="yes" | "no"
standalone="yes" | "no"
version="version_number"
/>
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
You can have zero or more
xsl:output
elements:
If there is more than one
xsl:output
element, the XSLT processor essentially combines the information.
If more than one
xsl:output
element sets the same attribute, the element with the highest import precedence will have its attribute selected.
If more than one
xsl:output
element repeats an attribute and has the same highest import precedence, either the last will be chosen or an error will be declared.
If there is more than one
cdata-section-elements
attribute, all of the values in the name lists will effectively be merged into one list.
The
xsl:output
element can only be a child of the
xsl:stylesheet
or the
xsl:transform
elements.
This is a self-closing element and it cannot contain any child elements or any content.
cdata-section-elements="namelist"
The optional
cdata-section-elements
attribute is set to a white-space delimited list of qnames (element names) whose content is to be output in CDATA sections. CDATA sections permit the use of sequences of characters that contain markup elements without violating the XML requirement to be well-formed (i.e., all tags and elements are closed).
doctype-public="string"
The optional
doctype-public
attribute specifies the public identifiers that go in the document type declaration (DTD). If the
doctype-system
attribute is not set, then the
doctype-public
attribute is ignored.
doctype-system="string"
The optional
doctype-system
attribute specifies the system identifiers that go in the document type declaration (DTD). The DTD should go immediately after the XML declaration.
encoding="string"
The optional
encoding
attribute specifies the preferred character encoding which is used to encode sequences of characters as sequences of bytes.
indent="yes" | "no"
The optional
indent
attribute specifies whether or not to indent. If set to yes, the XML and HTML outputs are step-indented to make them more readable.
media-type="mimetype"
The optional
media-type
attribute sets the MIME type. The default is:
media-type="text/xml"
method="html" | "qname" | "text" | "xml"
The optional
method
attribute dictates the type of output. The three permitted values are HTML, text and XML. (Some XSLT processors recognize a qname as being an acceptable value for this attribute, but it is not part of the W3C standard.) The default is XML. However, if the first child element of the root node is the HTML
<html>
tag and there are no preceding text nodes, then the default output type is set to HTML.
omit-xml-declaration="yes" | "no"
The optional
omit-xml-declaration
attribute dictates whether the XSLT processor should output an XML declaration. The default is no and an XML declaration is output. If yes, there is no output.
standalone="yes" | "no"
The optional
standalone
attribute dictates whether the XSLT processor should output a standalone declaration. Yes signifies that it will. No, the default, signifies that it will not.
version="version_number"
The optional
version
attribute provides the W3C version number for the output format. If the output is XML, the default version is 1.0 (currently, the only X3C version). Or if the output type is HTML, the default version is 4.0.
We use the
DevGuru Staff List XML file
for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_output.xsl"?>
and we name it: xslt_example_output.xml
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.)
Code for xslt_example_output.xsl:
<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>
Output:
Click to view output in separate window
- requires Internet Explorer
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information