Main Page

XSL processor

As you can see, the value passed in through JavaScript is correctly output to the HTML result. If you use
parameters in this way, you can make style sheets more extensible by incorporating different behaviors
based on parameters.
Another advanced feature of the XSL processor is the capability to set a mode of operation. In XSLT,
it’s possible to define a mode for a template. When a
is defined, the template isn’t run unless
<xsl:apply-templates />
is specifically called with its
attribute. For example:
<xsl:stylesheet version=”1.0” xmlns:xsl=””>
<xsl:output method=”html” />
<xsl:param name=”message” />
<xsl:template match=”/”>
<xsl:apply-templates select=”*” />
<p>Message: <xsl:value-of select=”$message” /></p>
<xsl:template match=”employee”>
<li><xsl:value-of select=”name” />, <em><xsl:value-of select=”@title”
<xsl:template match=”employee” mode=”position-first”>
<li><em><xsl:value-of select=”@title” /></em>, <xsl:value-of select=”name”
This style sheet defines a template with its
attribute set to
(note that you can
name a mode whatever you want; there are no predefined modes). Inside of this template, the employee’s
position is output first, and the employee name is output second. In order to use this template, the
element must have its
to “position-first”
as well. If you use
this style sheet, it has the same output as the previous one, displaying the employee name first and the
position second. If, however, you use this style sheet and set the mode to
JavaScript, it outputs the employee’s position first:
oProcessor.input = oXmlDom;
oProcessor.addParameter(“message”, “Hello World!”);
Chapter 15
18_579088 ch15.qxd 3/28/05 11:42 AM Page 476

JavaScript EditorFree JavaScript Editor     Ajax Editor