Latest web development tutorials

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元素參考手冊