非常教程

XSLFO 教程教程

XSLT <xsl:when> 元素

XSLT <xsl:when> 元素

XSLT <xsl:when> 元素


XSLT <xsl:when> 元素

完整的 XSLT 元素参考手册

定义和用法

<xsl:when> 元素用于为 <xsl:choose> 元素规定相关动作。 <xsl:when> 元素会计算一个表达式,如果返回 true,则执行规定的动作。

注意:<xsl:when> 元素与 <xsl:choose> 元素和 <xsl:otherwise> 元素协同使用,来表达多个条件测试。


语法

<xsl:when
test="boolean-expression">

<!-- Content: template -->

</xsl:when>

属性

属性 描述
test boolean-expression 必需。规定要测试的布尔表达式。

实例 1

下面的代码会在 cd 的价格高于 10 时向 artist 列添加粉色的背景色。

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<xsl:choose>
<xsl:when test="price&gt;'10'">
<td bgcolor="#ff00ff">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="artist"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

查看 XML 文件、 查看 XSL 文件、 查看结果。

实例 2

声明了一个名为 "color" 的变量。把它的值赋给当前元素的 color 属性。如果当前元素没有 color 属性,则 "color" 的值将是 "green":

<xsl:variable name="color">
<xsl:choose>
<xsl:when test="@color">
<xsl:value-of select="@color"/>
</xsl:when>
<xsl:otherwise>green</xsl:otherwise>
</xsl:choose>
</xsl:variable>


XSLT <xsl:when> 元素

完整的 XSLT 元素参考手册
XSLT <xsl:when> 元素
XSLFO 教程

XSL-FO,即可扩展样式表语言格式化对象(Extensible Stylesheet Language Formatting Objects),是用于格式化 XML 数据的语言。XSL-FO 是一个 W3C 推荐标准。

XSLFO 教程目录

1.XSLT 教程
2.XSL-FO 教程
3.XSLT <xsl:value-of> 元素
4.XSLT <xsl:template> 元素
5.XSLT 转换
6.XSLT 浏览器
7.XSLT 简介
8.XSL 语言
9.XSLT 在服务器端
10.XSLT 在客户端
11.XSLT <xsl:apply-templates> 元素
12.XSLT <xsl:choose> 元素
13.XSLT <xsl:if> 元素
14.XSLT <xsl:sort> 元素
15.XSLT <xsl:for-each> 元素
16.XSLT 总结
17.XML 编辑器
18.XSLT – 编辑 XML
19.XSLT <xsl:comment> 元素
20.XSLT <xsl:choose> 元素
21.XSLT <xsl:call-template> 元素
22.XSLT <xsl:attribute-set> 元素
23.XSLT <xsl:attribute> 元素
24.XSLT <xsl:apply-templates> 元素
25.XSLT <xsl:apply-imports> 元素
26.XSLT 实例
27.XSLT <xsl:import> 元素
28.XSLT <xsl:if> 元素
29.XSLT <xsl:for-each> 元素
30.XSLT <xsl:fallback> 元素
31.XSLT <xsl:element> 元素
32.XSLT <xsl:decimal-format> 元素
33.XSLT <xsl:copy-of> 元素
34.XSLT <xsl:copy> 元素
35.XSLT <xsl:otherwise> 元素
36.XSLT <xsl:number> 元素
37.XSLT <xsl:namespace-alias> 元素
38.XSLT <xsl:message> 元素
39.XSLT <xsl:key> 元素
40.XSLT <xsl:include> 元素
41.XSLT <xsl:variable> 元素
42.XSLT <xsl:value-of> 元素
43.XSLT <xsl:text> 元素
44.XSLT <xsl:template> 元素
45.XSLT <xsl:stylesheet> 和 <xsl:transform> 元素
46.XSLT <xsl:sort> 元素
47.XSLT <xsl:processing-instruction> 元素
48.XSLT <xsl:preserve-space> 和 <xsl:strip-space> 元素
49.XSLT <xsl:param> 元素
50.XSLT <xsl:output> 元素
51.XSLT key() 函数
52.XSLT generate-id() 函数
53.XSLT function-available() 函数
54.XSLT format-number() 函数
55.XSLT element-available() 函数
56.XSLT document() 函数
57.XSLT current() 函数
58.XSLT 元素参考手册
59.XSLT <xsl:with-param> 元素
60.XSLT <xsl:when> 元素
61.XSL-FO 流
62.XSL-FO 输出
63.XSL-FO 区域属性
64.XSL-FO 文档
65.XSL-FO 简介
66.XSLT 函数
67.XSLT unparsed-entity-uri() 函数
68.XSLT system-property() 函数
69.XSL-FO 软件
70.XSL-FO 与 XSLT
71.XSL-FO 表格
72.XSL-FO 列表
73.XSL-FO block 对象
74.XSL-FO bidi-override 对象
75.XSL-FO basic-link 对象
76.XSL-FO flow 对象
77.XSL-FO float 对象
78.XSL-FO external-graphic 对象
79.XSL-FO declarations 对象
80.XSL-FO conditional-page-master-reference 对象
81.XSL-FO color-profile 对象
82.XSL-FO character 对象
83.XSL-FO block-container 对象
84.XSL-FO inline-container 对象
85.XSL-FO inline 对象
86.XSL-FO initial-property-set 对象
87.XSL-FO footnote-body 对象
88.XSL-FO footnote 对象
89.XSL-FO list-item-label 对象
90.XSL-FO list-item-body 对象
91.XSL-FO list-item 对象
92.XSL-FO list-block 对象
93.XSL-FO leader 对象
94.XSL-FO layout-master-set 对象
95.XSL-FO instream-foreign-object 对象
96.XSL-FO multi-case 对象
97.XSL-FO marker 对象
98.XSL-FO region-before 对象
99.XSL-FO region-after 对象
100.XSL-FO page-sequence-master 对象