XSLT <xsl:anahtar>
❮ XSLT Öğe Referansını Tamamlayın
Tanım ve Kullanım
<xsl:key> öğesi, stil sayfasında key() işleviyle kullanılabilecek adlandırılmış bir anahtar bildiren üst düzey bir öğedir.
Not: Bir anahtarın benzersiz olması gerekmez!
Sözdizimi
<xsl:key
name="name"
match="pattern"
use="expression"/>
Öznitellikler
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 |
örnek 1
"persons.xml" adında bir XML dosyanız olduğunu varsayalım:
<persons>
<person name="Tarzan" id="050676"/>
<person name="Donald" id="070754"/>
<person name="Dolly" id="231256"/>
</persons>
Bir XSL dosyasında şöyle bir anahtar tanımlayabilirsiniz:
<xsl:key name="preg" match="person" use="@id"/>
id="050676" olan kişiyi bulmak için şunu yazın (XSL dosyasına):
<?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>
❮ XSLT Öğe Referansını Tamamlayın