Text output mode

The techniques described above are complex and untidy. Fortunately, the XSLT standard includes a mechanism that makes output of non-XML data much simpler. However, this is an optional mechanism, and so a particular XSLT processor may not support it. In this circumstance, the techniques described above must be used instead.

Some XSLT processors (and hopefully most) will support the 'text mode' option. In this mode, none of the reserved escape characters is converted into its entity reference form ('&', '<' or '>'). This makes the Disable Output Escaping attribute redundant (if it is present at all). The main reason why this mode may not be supported is that some XSLT processors will not have control over the actual outputting of data.

The Output element is used to specify text format output. The Method attribute is given the value 'text':

<transform ...>
  <output
					method="text"/>
  ...
<transform>

When the required output resembles XML, it is important to note that text that resembles element start-tags and end-tags is not copied to output. The first example below does not add any prefix or suffix to the content of the element. The second example works as expected:

<xsl:template match="title">
  <!-- DOES NOT WORK -->
  <TITLE><xsl:apply-templates/></TITLE>
</xsl:template>

<xsl:template match="title">
  &lt;TITLE&gt;<xsl:apply-templates/>&lt;/TITLE&gt;
</xsl:template>

The Media Type attribute can be used in this scenario. The default value is 'text/plain':

<output method="text" media-type="text/xyz" />

The Encoding attribute can be used to specify how to represent special characters. If one or more characters in the source data cannot be represented by the format specified, the XSLT processor should report an error:

<output method="text" encoding="ISO-8859-1/" />

Extended characters can be specified in the template using the '&#…;' mechanism. This same mechanism is very useful in the following circumstance.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.149.116