↑
Main Page
style sheet
<xsl:param name=”message” />
<xsl:template match=”/”>
<html>
<head>
<title>Employees</title>
</head>
<body>
<ul>
<xsl:apply-templates select=”*” />
</ul>
<p>Message: <xsl:value-of select=”$message” /></p>
</body>
</html>
</xsl:template>
<xsl:template match=”employee”>
<li><xsl:value-of select=”name” />, <em><xsl:value-of select=”@title”
/></em></li>
</xsl:template>
</xsl:stylesheet>
This style sheet adds two lines of code. The first is an
<xsl:param/>
element that defines a parameter
named
message
. The second line outputs the
message
by using the
<xsl:value-of/>
element (the
dollar sign indicates that this is a local variable, not an element or an attribute).
To set the value of
message
, you use the
addParameter()
method before calling
transform()
. The
addParameter()
method takes two arguments, the name of the parameter to set (as specified in
<xsl:param/>
’s name attribute) and the value to assign it (most often a string, but can be a number or
Boolean as well):
oProcessor.input = oXmlDom.documentElement;
oProcessor.addParameter(“message”, “Hello World!”);
oProcessor.transform();
By setting a value for the parameter, the output now becomes the following:
<html>
<head>
<title>Employees</title>
</head>
<body>
<ul>
<li>Nicholas C. Zakas, <em>Software Engineer</em></li>
<li>Jim Smith, <em>Salesperson</em></li>
</ul>
<p>Message: Hello World!</p>
</body>
</html>
475
XML in JavaScript
18_579088 ch15.qxd 3/28/05 11:42 AM Page 475
Free JavaScript Editor
Ajax Editor
©
→