XSLT <xsl:key> Element

The XSLTelement 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

IndexNameDescription
1)NameIt specifies the name of the key to be used.
2)MatchIt specifies that the pattern must be matched to a node that holds this key.
3)UseIt 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:

XSLT Xsl key element 1
Next TopicXSLT <message>




Latest Courses