<xsl: choose> <xsl: when test ="Boolean expression"> <xsl: when test ="Boolean expression"> <xsl:otherwise> </xsl: choose>
每个 <xsl: when> 元素都有一个测试条件。测试条件是一个布尔表达式,而布尔表达式是转换为布尔值的 XPath 表达式。其测试条件成立的第一个 <xsl: when> 元素的内容将输出至结果树。
另外,<xsl: choose> 元素可具有可选的 <xsl:otherwise> 元素,仅当任何 <xsl: when> 元素的测试条件都不成立时,才会输出 <xsl:otherwise> 元素的内容。如果不存在 <xsl:otherwise> 元素,并且任何 <xsl: when> 子元素中的测试条件都不成立,则 <xsl: choose> 元素不会产生任何输出。
下面是 <xsl: choose> 元素的一个示例:
<xsl: choose> <xsl: when test = "number [ . > 2000]">A big number</xsl:when> <xsl:otherwise>A small number</xsl:otherwise> </xsl:choose>
如果目标 XML 文件中的数字元素包含一个大于 2,000 的数值,则会将字符串“A big number”插入到结果树中。在其他任何情况下,将插入“A small number”。
下列指示信息是为“资源”透视图编写的,但是也将适用于其他多个透视图。
要创建 <xsl: choose> 元素,遵循下列步骤: