May 28, 2021 XSL T
The XSLT-lt;xsl:key-gt; element is used to declare a key that is used by the key() function.
The element is a top-level element that declares a named key (that is, the name and value pair assigned to the element specified in the XML document). The key is used in style sheets by the key() function to help you effectively access assigned elements in complex XML documents.
Note: Keys don't have to be unique!
Attributes | value | describe |
---|---|---|
name | name | Required.The name of the specified key. |
match | pattern | Required.Define which node is applied to. |
use | expression | Required.Specifies the expression that is used as the value of the keys to each node. |
Suppose you have an XML file .xml "persons":
You can define a key in the XSL file as follows:
To find the person with id "050676", use these codes (in the XSL file):