XSLT องค์ประกอบ <xsl:apply-templates>
การประกาศและการใช้งาน
element <xsl:apply-templates> สามารถปฏิบัติแบบภาพใน element ปัจจุบันหรือใน element ลูกของ element ปัจจุบัน
ถ้าเราเพิ่มคุณสมบัติ select ใน element <xsl:apply-templates> มันจะปฏิบัติเพียงแค่เอกซ์เท็มเพลนที่ตรงกับค่าของคุณสมบัตินี้ พวกเราสามารถใช้คุณสมบัติ select มากำหนดลำดับที่จะปฏิบัติตามมีส่วนย่อย
ศัพท์
<xsl:apply-templates select="expression" mode="name"> <!-- Content:(xsl:sort|xsl:with-param)* --> </xsl:apply-templates>
แบบภาพ
แบบภาพ | ค่า | คำอธิบาย |
---|---|---|
select | รายละเอียด | ให้เลือก。กำหนดหุ้นตัวที่ต้องการปฏิบัติ |
mode | ชื่อ | ให้เลือก。ถ้ามีหลายกลวิธีการปฏิบัติสำหรับ element ที่เดียวกัน ใช้ mode ที่จะแยกความแตกต่างเข้ากัน |
ตัวอย่าง
ตัวอย่าง 1
ใช้สัญญาณ h1 ล้อมรายการที่แต่ละตัวของ element title ในเอกสาร:
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" <xsl:template match="title"> <h1><xsl:apply-templates/></h1> </xsl:template> </xsl:stylesheet>
ตัวอย่าง 2
ใช้องค์ประกอบ h1 มอดว่างรอบทุกตัวหลักทั้งหมดของ sub-element ที่เป็น title ของ message
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" <xsl:template match="message"> <h1><xsl:apply-templates select="title"/></h1> </xsl:template> </xsl:stylesheet>
ตัวอย่าง 3
ใช้องค์ประกอบ h1 มอดว่างรอบทุกตัวหลักทั้งหมดของ message ที่มีค่าของมอดในแบบ "big"
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" <xsl:template match="message"> <h1><xsl:apply-templates select="*" mode="big"/></h1> </xsl:template> </xsl:stylesheet>