एक्सएसएलटी <xsl:कुंजी>
❮ पूर्ण एक्सएसएलटी तत्व संदर्भ
परिभाषा और उपयोग
<xsl:key> तत्व एक शीर्ष-स्तरीय तत्व है जो एक नामित कुंजी की घोषणा करता है जिसे कुंजी () फ़ंक्शन के साथ स्टाइल शीट में उपयोग किया जा सकता है।
नोट: एक कुंजी का अद्वितीय होना आवश्यक नहीं है!
वाक्य - विन्यास
<xsl:key
name="name"
match="pattern"
use="expression"/>
गुण
Attribute | Value | Description |
---|---|---|
name | name | Required. Specifies the name of the key |
match | pattern | Required. Defines the nodes to which the key will be applied |
use | expression | Required. The value of the key for each of the nodes |
उदाहरण 1
मान लीजिए कि आपके पास "persons.xml" नाम की एक XML फ़ाइल है:
<persons>
<person name="Tarzan" id="050676"/>
<person name="Donald" id="070754"/>
<person name="Dolly" id="231256"/>
</persons>
आप इस तरह एक एक्सएसएल फ़ाइल में एक कुंजी परिभाषित कर सकते हैं:
<xsl:key name="preg" match="person" use="@id"/>
आईडी = "050676" वाले व्यक्ति को खोजने के लिए (XSL फ़ाइल में) लिखें:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="preg" match="person" use="@id"/>
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="key('preg','050676')">
<p>
Id: <xsl:value-of select="@id"/><br />
Name: <xsl:value-of select="@name"/>
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
❮ पूर्ण एक्सएसएलटी तत्व संदर्भ