当前位置: 首页 > 网络学院 > XML相关教程 > XSL/XSLT > XSLT <xsl:variable> 元素

XSL/XSLT
XSL 语言
XSLT 介绍
XSLT 浏览器
XSLT 转换
<xsl:template>
<xsl:value-of>
<xsl:for-each>
<xsl:sort>
<xsl:if>
<xsl:choose>
<xsl:apply-templates>
XSLT - 客户端
XSLT - 服务器端
XSLT - 编辑XML
XSLT 摘要
XSLT 元素参考
XSLT 函数
XSL 编辑器

XSL/XSLT 中的 XSLT <xsl:variable> 元素


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 220 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The <xsl:variable> element is used to declare a local or global variable.
<xsl:variable> 元素的作用是:生命一个本地或全局变量。

Note: The variable is global if it's declared as a top-level element, and local if it's declared within a template.
注意:如果它是以最顶级元素的方式声明的,那么它是一个全局变量;如果它是在一个模版中声明的,那么它是一个本地变量。

Note: Once you have set a variable's value, you cannot change or modify that value!
注意:当你设置一个变量值时,你不能改变或更正该变量值。

Tip: You can add a value to a variable by the content of the <xsl:variable> element OR by the select attribute!
提示:你可以通过 <xsl:variable>元素或通过select[选择]属性向一个变量中添加一个值。


Syntax
语法

<xsl:variable
name="name"
select="expression">
 <!-- Content:template -->
</xsl:variable>

Attributes
属性

属性 描述
name name Required. Specifies the name of the variable
必要参数。指定变量名称
select expression Optional. Defines the value of the variable
可选参数。定义变量值

Example 1
案例1

If the select attribute is present, the <xsl:variable> element cannot contain any content. If the select attribute contains a literal string, the string must be within quotes. The following two examples assign the value "red" to the variable "color":
如果Select[选择]属性存在,那么<xsl:variable>元素中则不能包含任何内容;如果Select[选择]属性包含了一个纯文本字符串,那么该字符串必须写在引号("")内。县勉的两个案例向“color[颜色]”变量中指定了“red[红色]”值:

<xsl:variable name="color" select="'red'" />

<xsl:variable name="color" select='"red"' />

Example 2
案例2

If the <xsl:variable> element only contains a name attribute, and there is no content, then the value of the variable is an empty string:
如果<xsl:variable> 元素仅包含一个name属性,并且不包含任何内容,那么变量值是一个空字符串:

<xsl:variable name="j" />

Example 3
案例3

The following example adds a value to the variable "header" by the content of the <xsl:variable> element:
在下面的案例中,我们通过<xsl:variable>元素向“header”变量中添加了一个值:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="header"> <tr> <th>Element</th> <th>Description</th> </tr>
</xsl:variable>
<xsl:template match="/"> <html> <body> <table> <xsl:copy-of select="$header" /> <xsl:for-each select="reference/record"> <tr> <xsl:if category="XML"> <td><xsl:value-of select="element"/></td> <td><xsl:value-of select="description"/></td> </xsl:if> </tr> </xsl:for-each> </table> <br /> <table> <xsl:copy-of select="$header" /> <xsl:for-each select="table/record"> <tr> <xsl:if category="XSL"> <td><xsl:value-of select="element"/></td> <td><xsl:value-of select="description"/></td> </xsl:if> </tr> </xsl:for-each> </table> </body> </html>
</xsl:template>
</xsl:stylesheet>

评论 (0) All

登陆 | 还没注册?