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

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:key> 元素


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

Definition and Usage
定义和用法

The <xsl:key> element is a top-level element which declares a named key that can be used in the style sheet with the key() function.
<xsl:key> 元素是一个顶级元素,它是用来声明一个指定的键[key]的。该键所对应的函数是key()函数,它可以被用在样式表中。

Note: A key does not have to be unique!
注意:键[key]不具有唯一性。


Syntax
语法

<xsl:key
name="name"
match="pattern"
use="expression"/>

Attributes
属性

属性 描述
name name Required. Specifies the name of the key
必要参数。指定键名称
match pattern Required. Defines the nodes to which the key will be applied
必要参数。定义键所应用的节点(即:该键对哪个节点起作用)
use expression Required. The value of the key for each of the nodes
必要参数。为每个节点指定键值

Example 1
案例1

Suppose you have an XML file called "persons.xml":
假设你创建了一个名为 "persons.xml"的XML文件:

<persons> <person name="Tarzan" id="050676"/> <person name="Donald" id="070754"/> <person name="Dolly" id="231256"/>
</persons>

You can define a key in an XSL file like this:
你可以像下面一样给XSL文件定义一个键:

<xsl:key name="preg" match="person" use="@id"/>

To find the person with id="050676", write (in the XSL file):
查找XSL文件中id=="050676"的人:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="preg" match="person" use="@id"/>
<xsl:template match="/"> <html> <body> <xsl:for-each select="key('preg','050676')"> <p> Id: <xsl:value-of select="@id"/><br /> Name: <xsl:value-of select="@name"/> </p> </xsl:for-each> </body> </html>
</xsl:template>
</xsl:stylesheet>

评论 (0) All

登陆 | 还没注册?