xsl:output

<xsl:output>
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.
<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"

/>

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 eBIZ.com Staff 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:
<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE xsl:stylesheet  [

	<!ENTITY nbsp   " ">

	<!ENTITY copy   "©">

	<!ENTITY reg    "®">

	<!ENTITY trade  "™">

	<!ENTITY mdash  "—">

	<!ENTITY ldquo  "“">

	<!ENTITY rdquo  "”"> 



	<!ENTITY pound  "£">

	<!ENTITY yen    "¥">



	<!ENTITY euro   "€">



]>



<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 xmlns="http://www.w3.org/1999/xhtml">

<head>



<script>



var i=0;



function mm() {



i+=1;



document.data.srno.innerHTML=""+i;



}

</script> 

<meta http-equiv="Content-Type" 

content="text/html; charset=iso-8859-1"/>

<title>Sample XSL Document</title>

<style type="text/css">

<xsl:comment>



.style3 {font-family: Geneva, Arial,

 Helvetica, sans-serif; color: #0033FF; }



</xsl:comment>



</style>



</head>



<body>



	



<table width="59%" border="1" 

cellspacing="0" cellpadding="1" id="data">



  <tr>



    <td width="9%" nowrap="nowrap" 


bgcolor="#6699FF"><strong>Sr no </strong></td>



    <td width="22%" bgcolor="#6699FF">


<strong>Employee ID </strong></td>



	<td width="30%" bgcolor="#6699FF"


><strong>Name</strong></td>

    

    <td width="20%" bgcolor="#6699FF">



<strong>Department</strong></td>

   

    <td width="19%" bgcolor="#6699FF">


<strong>Designation</strong></td>



	<td width="19%" nowrap="nowrap" 




bgcolor="#6699FF"><strong>Phone No </strong></td>



	<td width="19%" nowrap="nowrap


" bgcolor="#6699FF"><strong>Address </strong></td>



  </tr>

<xsl:for-each select="ebiz/employee_details">



	<tr>

<td><xsl:number value="position()" format="A. " /></td>

     <td nowrap="nowrap"><span class="style3">

<xsl:value-of select="emp_id" /></span></td>

	 <td nowrap="nowrap"><span class="style3"

><xsl:value-of select="fname"> </xsl:value-of>

<xsl:value-of select="lname"></xsl:value-of></span></td>

   

    <td nowrap="nowrap"><xsl:value-of select="department" /></td>

    

    <td nowrap="nowrap"><xsl:value-of select="designation" /></td>

	<td nowrap="nowrap"><xsl:value-of select="phone" /></td>

	<td nowrap="nowrap"><xsl:value-of select="address"/></td>

  </tr></xsl:for-each>

</table>

 

</body>

</html>



</xsl:template>



</xsl:stylesheet>