Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XSLT Element

XSLT xsl:key Element


XSLT Element Reference Manual Complete XSLT Element Reference Manual


Definition and Usage

The xsl:key element is a top-level element that declares a named key (that is, a name/value pair assigned to specified elements in an XML document). The key is used in the style sheet through the key() function, helping you efficiently access the assigned elements in complex XML documents.

**Note:** A key does not have to be unique!


Syntax

name="name"

match="pattern"

use="expression"/>

property

property Value Description
name name Required. Specifies the name of the key.
match pattern Required. Defines the nodes to which the key is applied.
use expression Required. Specifies the expression to use as the value of the key for each node.

Example 1

Suppose you have an XML file named "persons.xml":

You can define a key in the XSL file as follows:

To find the person with id="050676", use this code (in the XSL file):

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

Id:

Name:


XSLT Element Reference Manual Complete XSLT Element Reference Manual