XSLT <XSL นำเข้า> องค์ประกอบ
ความหมายและการใช้งาน
<xsl: Import> องค์ประกอบเป็นองค์ประกอบชั้นนำสำหรับเนื้อหาของสไตล์ชีตลงในสไตล์ชีตอื่น
หมายเหตุ: การจัดลำดับความสำคัญของแผ่นสไตล์นำเข้าต่ำกว่าสไตล์ชีตส่งออก
หมายเหตุ: องค์ประกอบนี้จะต้องเป็น <XSL: สไตล์ชีต> หรือ <XSL: เปลี่ยน> เป็นโหนดลูกคนแรก
ไวยากรณ์
<xsl:import href="URI"/>
คุณสมบัติ
属性 | 值 | 描述 |
---|---|---|
href | URI | 必需。规定要导入的样式表的 URI。 |
ตัวอย่างที่ 1
สมมติว่าคุณมีแผ่นลักษณะที่ชื่อ "cdcatalog_ex3.xsl" ของ:
<?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="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td><xsl:value-of select="catalog/cd/title"/></td>
<td><xsl:value-of select="catalog/cd/artist"/></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td><xsl:value-of select="catalog/cd/title"/></td>
<td><xsl:value-of select="catalog/cd/artist"/></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
ที่สองเรียกว่า "cdcatalog_import.xsl" สไตล์ชีตจะนำเข้า "cdcatalog_ex3.xsl":
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="cdcatalog_ex3.xsl"/>
<xsl:template match="/">
<xsl:apply-imports/>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="cdcatalog_ex3.xsl"/>
<xsl:template match="/">
<xsl:apply-imports/>
</xsl:template>
</xsl:stylesheet>
ดูไฟล์ XML , ดูไฟล์ XSL , ดูผลลัพธ์
หมายเหตุ: ตัวอย่างนี้ไม่สามารถทำงานใน Netscape 6, Netscape 6 ไม่สนับสนุนเพราะ <XSL: ใช้-การนำเข้า> องค์ประกอบ!
คู่มือการใช้งาน XSLT ธาตุอ้างอิงที่สมบูรณ์