XSLT <xsl:key> Element
The XSLT element is used to specify a named name-value pair assigned to a specific element in an XML document. This key is used with the key() function in XPath expressions to access the assigned elements in an XML document.
Parameter explanation
Index | Name | Description |
---|---|---|
1) | Name | It specifies the name of the key to be used. |
2) | Match | It specifies that the pattern must be matched to a node that holds this key. |
3) | Use | It specifies XPath expression to identify the value of the nodes of xml document. |
XSLT <xsl:key> Element Example
Let’s take an example to create a table of <employee> element with its attribute “id”and its child <firstname>, <lastname>, <nickname>, and <salary> by iterating over each employee. This example checks key as firstname to be one of the employee’s name and then prints the employee’s details.
Employee.xml
Employee.xsl
Output:
Next TopicXSLT <message>