XSLT <xsl:import> 元素


XSLT 元素參考手冊 完整的 XSLT 元素參考手冊

定義和用法

<xsl:import> 元素是頂層元素,用於把一個樣式表中的內容導入另一個樣式表中。

注意:被導入的樣式表的優先順序低於導出的樣式表。

注意:該元素必須是 <xsl:stylesheet> 或 <xsl:transform> 的第一個子節點。


語法

<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> 元素!


XSLT 元素參考手冊 完整的 XSLT 元素參考手冊