| only for RuBoard |
xsl:otherwise provides a default for multiple condition testing, used with the xsl:choose and xsl:when elements. A similar construct is the else keyword in most programming languages that is used with an if statement.
None.
Suppose that you want to create a numbered outline from the data in an XML file. Consider the following XML file, links.xml :
<links>
<link name="NewRiders.com" URL="http://www.newriders.com"> />
<link name="Xmlandasp.net" URL="http://www.xmlandasp.net" />
<link name="MSDN Online Library" URL="http://msdn.microsoft.com/library"
/>
</links>
Specify that you are outputting version 4.0 HTML and do not want an XML declaration at the beginning of the output:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head></head>
<body></body>
<table>
<xsl:apply-templates />
</table>
</html>
</xsl:template>
<xsl:template match="link">
<tr>
<td>
<xsl:value-of select="@name" />
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
Applying the stylesheet to links.xml would produce version 4.0-compliant HTML. Notice the meta tag generated that specifies the content type, and the lack of an XML declaration at the beginning of the HTML output:
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">
</head>
<body>
</body>
<table>
<tr>
<td>
NewRiders.com
</td>
</tr>
<tr>
<td>
Xmlandasp.net
</td>
</tr>
<tr>
<td>
MSDN Online Library
</td>
</tr>
</table>
</html>
xsl:choose
xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements
| only for RuBoard |
| only for RuBoard |
xsl:param provides a variable parameter for an xsl:stylesheet or an xsl:tem plate element.
The xsl:param element is identical to the xsl:variable element, except that the xsl:param element can specify a default value.
|
Attribute
|
Enforced |
Description |
Values |
|---|---|---|---|
|
method |
Optional |
Specifies the overall method that should be used for outputting the result tree. |
xml , html , text , or any QName that is not an NCName . |
|
version |
Optional |
Specifies the version of the output method |
NMToken |
|
encoding |
Optional |
Specifies the preferred character encoding that the XSLT processor should use to encode sequences of
|
The value must contain only charac ters in the range #x21 to #x7E (for example, printable ASCII characters); the value should either be a charset registered with the Internet Assigned Numbers Authority, RFC2278, or start with X . |
|
omit-xml- declaration |
Optional |
Specifies whether the XSLT processor should emit an XML declaration. |
yes or no . |
|
standalone |
Optional |
Indicates if the XSLT processor should output a standalone document declaration. The default is no . |
yes or no . |
|
doctype-public |
Optional |
Specifies the public identifier to be used in the document type declaration. |
String |
|
doctype-system |
Optional |
Specifies the system identifier to be used in the document type declaration. |
String |
|
cdata-section- elements |
Optional |
Specifies a list of element
|
QNames |
|
indent |
Optional |
Indicates if the XSLT processor might add additional white space when outputting the result tree. |
yes or no . |
|
media-type |
Optional |
Specifies the MIME content type of the data that results from outputting the result tree. |
String |
Suppose that you want to display an HTML table with alternating rows colored differently. One way to do this is to set up a template rule that accepts the
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head></head>
<body></body>
<table>
<xsl:for-each select="links/link">
<xsl:choose>
<xsl:when test="position() mod 2 = 0">
<xsl:call-template name="output-row" />
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="output-row">
<xsl:with-param name="bgcolor" select="'silver'"
/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</table>
</html>
</xsl:template>
<xsl:template name="output-row">
<xsl:param name="bgcolor" select="'blue'" />
<tr>
<xsl:attribute name="bgcolor">
<xsl:value-of select="$bgcolor" />
</xsl:attribute>
<td>
<xsl:value-of select="@name" />
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
This stylesheet emits the following results. Notice that the odd-numbered rows have the specified color of silver , while the even-numbered rows have the default color of blue .
<html> <head> <META http-equiv="Content-Type" content="text/html; charset=UTF-16"> </head> <body></body> <table> <tr bgcolor="silver"> <td>NewRiders.com</td> </tr> <tr bgcolor="blue"> <td>Xmlandasp.net</td> </tr> <tr bgcolor="silver"> <td>MSDN Online Library</td> </tr> </table> </html>
xsl:stylesheet, xsl:template, xsl:transform
xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements
| only for RuBoard |