คีย์ XSLT () ฟังก์ชั่น
❮ การอ้างอิงฟังก์ชัน XSLTความหมายและการใช้งาน
ฟังก์ชัน key() ส่งคืนชุดโหนดจากเอกสาร โดยใช้ดัชนีที่ระบุโดยองค์ประกอบ <xsl:key>
ไวยากรณ์
node-set key(string, object)
พารามิเตอร์
Parameter | Description |
---|---|
string | Required. Specifies the name of an xsl:key element |
object | Required. A string to search for |
ตัวอย่าง 1
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="cdlist" match="cd" use="title" />
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="key('cdlist', 'Empire Burlesque')">
<p>
Title: <xsl:value-of select="title" />
<br />
Artist: <xsl:value-of select="artist" />
<br />
Price: <xsl:value-of select="price" />
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
ดูไฟล์ XMLดู ไฟล์ XSLและ ดูผลลัพธ์
❮ การอ้างอิงฟังก์ชัน XSLT