XSLT สร้าง-id ()ฟังก์ชัน
❮ การอ้างอิงฟังก์ชัน XSLTความหมายและการใช้งาน
ฟังก์ชัน generate-id() ส่งคืนค่าสตริงที่ระบุโหนดที่ระบุโดยไม่ซ้ำกัน
หากชุดโหนดที่ระบุว่างเปล่า ระบบจะส่งคืนสตริงว่าง หากคุณละเว้นพารามิเตอร์ node-set ค่าดีฟอลต์จะเป็นโหนดปัจจุบัน
ไวยากรณ์
string generate-id(node-set?)
พารามิเตอร์
Parameter | Description |
---|---|
node-set | Optional. Specifies on which node-set to generate a unique id |
ตัวอย่าง 1
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h3>Artists:</h3>
<ul>
<xsl:for-each select="catalog/cd">
<li>
<a href="#{generate-id(artist)}">
<xsl:value-of select="artist" /></a>
</li>
</xsl:for-each>
</ul>
<hr />
<xsl:for-each select="catalog/cd">
Artist: <a id="{generate-id(artist)}">
<xsl:value-of select="artist" /></a>
<br />
Title: <xsl:value-of select="title" />
<br />
Price: <xsl:value-of select="price" />
<hr />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
ดูไฟล์ XMLดูไฟล์ XSLและ ดูผลลัพธ์
❮ การอ้างอิงฟังก์ชัน XSLT