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.NoName & 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 OccurrencesUnlimited
Parent elementsxsl:stylesheet
Child elementsNone

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

Output

XML Tutorial

XML HOMEXML IntroductionXML How to useXML TreeXML SyntaxXML ElementsXML AttributesXML NamespacesXML DisplayXML HttpRequestXML ParserXML DOMXML XPathXML XSLTXML XQueryXML XLinkXML ValidatorXML DTDXML SchemaXML ServerXML ExamplesXML QuizXML Certificate

XML AJAX

AJAX IntroductionAJAX XMLHttpAJAX RequestAJAX ResponseAJAX XML FileAJAX PHPAJAX ASPAJAX DatabaseAJAX ApplicationsAJAX Examples

XML DOM

DOM IntroductionDOM NodesDOM AccessingDOM Node InfoDOM Node ListDOM TraversingDOM NavigatingDOM Get ValuesDOM Change NodesDOM Remove NodesDOM Replace NodesDOM Create NodesDOM Add NodesDOM Clone NodesDOM Examples

XPath Tutorial

XPath IntroductionXPath NodesXPath SyntaxXPath AxesXPath OperatorsXPath Examples

XSLT Tutorial

XSLT IntroductionXSL LanguagesXSLT TransformXSLT <template>XSLT <value-of>XSLT <for-each>XSLT <sort>XSLT <if>XSLT <choose>XSLT ApplyXSLT on the ClientXSLT on the ServerXSLT Edit XMLXSLT Examples

XQuery Tutorial

XQuery IntroductionXQuery ExampleXQuery FLWORXQuery HTMLXQuery TermsXQuery SyntaxXQuery AddXQuery SelectXQuery Functions

XML DTD

DTD IntroductionDTD Building BlocksDTD ElementsDTD AttributesDTD Elements vs AttrDTD EntitiesDTD Examples

XSD Schema

XSD IntroductionXSD How ToXSD <schema>XSD ElementsXSD AttributesXSD Restrictions

XSD Complex

XSD ElementsXSD EmptyXSD Elements OnlyXSD Text OnlyXSD MixedXSD IndicatorsXSD <any>XSD <anyAttribute>XSD SubstitutionXSD Example

Xsl Generate-id Key Example Template


XSD Data

XSD StringXSD DateXSD NumericXSD MiscXSD Reference

Web Services

XML ServicesXML WSDLXML SOAPXML RDFXML RSS

References

DOM Node TypesDOM NodeDOM NodeListDOM NamedNodeMapDOM DocumentDOM ElementDOM AttributeDOM TextDOM CDATADOM CommentDOM XMLHttpRequestDOM ParserXSLT ElementsXSLT/XPath Functions

Xsl Generate Id

Xsl Generate-id Key Example

Xsl Generate-id Key Examples