WebReference.com - Excerpt from Inside XSLT, Chapter 2, Part 5 (2/4) | WebReference

WebReference.com - Excerpt from Inside XSLT, Chapter 2, Part 5 (2/4)

To page 1current pageTo page 3To page 4
[previous] [next]

Inside XSLT

Output Method: HTML

The planets.xsl stylesheet we've been working with doesn't use the <xsl:output> element; it turns out that I've been relying on the default output rules with that stylesheet. By default, the output type is XML, unless the XSLT processor sees an <HTML> or <html> tag. (Note that this is not a formal requirement, just a convention, so you can't expect all XSLT processors to honor it.) I've used the <HTML> tag in planets.xsl like this:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="https://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/PLANETS">
    <HTML>
      <HEAD>
        <TITLE>
          The Planets Table
        </TITLE>
      </HEAD>
    .
    .
    .

However, if you remove this tag:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="https://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/PLANETS">
      <HEAD>
        <TITLE>
          The Planets Table
        </TITLE>
      </HEAD>
    .
    .
    .

Then this is the kind of output you'll get from James Clark's XT. Note the XML processing instruction at the beginning:

<?xml version="1.0" encoding="utf-8"?>
  <HEAD>
    <TITLE>
      The Planets Table
    </TITLE>
  </HEAD>
  .
  .
  .

On the other hand, you can explicitly specify the output type as HTML with the <xsl:output> element, even without using the <HTML> element:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="https://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>
  <xsl:template match="/PLANETS">
    <HEAD>
      <TITLE>
        The Planets Table
      </TITLE>
    </HEAD>
    .
    .
    .

Here's the output from XT in this case-just an HTML fragment, no XML processing instruction:

<HEAD>
  <TITLE>
    The Planets Table
  </TITLE>
</HEAD>
    .
    .
    .

Automatic <meta> Elements Added to HTML
If you do use the <xml:output method="html"/> element explicitly, some XSLT processors, such as Saxon, add a <meta> element to the output document's <head> element something like this:
<meta http-equiv= "Content-Type" content="text/html; charset=utf-8">.

In general, XSLT processors are supposed to realize that certain elements, such as <br>, <img>, <frame>, and so on are empty in HTML. Also, spaces and other characters in URI attribute values are converted as specified in the HTML specification (a space becomes "%20" and so on), processing instructions are terminated with > rather than ?>, and the fact that standalone attributes are not assigned a value is recognized.


To page 1current pageTo page 3To page 4
[previous] [next]

Created: October 11, 2001
Revised: October 11, 2001


URL: https://webreference.com/authoring/languages/xml/insidexslt/chap2/5/2.html