XSLT <xsl:import> 元素
定義和用法
<xsl:import> 元素是頂層元素,用于把一個樣式表中的內容倒入另一個樣式表中。
注釋:被導入的樣式的優(yōu)先級低于導出的樣式表。
注釋:該元素必須是 <xsl:stylesheet> 或 <xsl:transform> 的第一個子節(jié)點。
注釋:Netscape 6 不支持導入優(yōu)先規(guī)則,因此此元素的表現(xiàn)與 <xsl:include> 相同。
語法
<xsl:import href="URI"/>
屬性
屬性 | 值 | 描述 |
---|---|---|
href | URI | 必需。規(guī)定到導入的樣式表的 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 <xsl:attribute> 元素 下一篇: XSLT <xsl:preserve-space> 和 &l