Xsl Generate-id Key Example
You can use keys as generalized IDs for referencing elements in an XML document. To do this, first use xsl:key to declare a key for a node. Then call the key function to retrieve the node, supplying the name and value of the key as the function arguments. For more information, see the example below. Dec 21, 2016 Contribute to JayDaley/XML-to-JSON-in-XSLT development by creating an account on GitHub. This article walks throught the various choices you have in JSON output and provides example XSLT code for the various choices to form a construction kit that you can use to assemble an XSLT that works the way you want it to. Produced by this XSLT.
- The fn:key function returns the nodes with a particular key. It is similar to calling the fn:id function except using keys instead of IDs. Note: this is an XSLT-only function; it is not available in XQuery or XPath. Arguments and Return Type.
- On this page the XSLT function generate-id is described which generates an identifier (ID) for a node during the runtime of the stylesheet. XML technologies / XSLT / XSLT and XPath functions / Alphabetical XSLT and XPath reference / generate-id. Example - generating corresponding id anchors: xsl:template match='song'
- XSLT Tutorial
- XSLT Useful Resources
- Selected Reading
<xsl:key> tag element specifies 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.
Declaration
Following is the syntax declaration of <xsl:key> element.
Attributes
S.No | Name & Description |
---|---|
1 | Name Name of the key to be used. |
2 | Match Patterns used to identify a node that holds this key. |
3 | Use XPath expression to identify the value of the nodes of xml document. |
Elements
Number of Occurrences | Unlimited |
Parent elements | xsl:stylesheet |
Child elements | None |
Demo Example
This example creates a table of <student> element with its attribute rollno and its child <firstname>, <lastname>, <nickname>, and <marks> by iterating over each student. It checks key as firstname to be one of the student's name and then prints the student details.
students.xml
Ezbit info diablo key generator skidrow. students.xsl