องค์ประกอบ XSLT <xsl:import>

คำอธิบายและวิธีใช้

องค์ประกอบ <xsl:import> คือองค์ประกอบระดับสูงสุด ใช้ในการนำเข้าเนื้อหาของซาแฟร์จากซาแฟร์อื่น

註釋:ความสำคัญของซาแฟร์ที่นำเข้าต่ำกว่าซาแฟร์ที่ส่งออก

註釋:องค์ประกอบนี้ต้องเป็นตัวลูกแรกของ <xsl:stylesheet> หรือ <xsl:transform>

註釋:Netscape 6 ไม่สนับสนุนกฎการนำเข้าความสำคัญ ดังนั้นการแสดงขององค์ประกอบนี้เหมือนกับ <xsl:include>

วลี

<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>

ซาแฟร์ลูกที่สองชื่อว่า "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>

查看 XML 文件查看 XSL 文件查看結果

註釋:此例無法在 Netscape 6 运行,因為 Netscape 6 不支持 <xsl:apply-imports> 元素!