Latest web development tutorials

XSLT <xsl:apply-imports> 元素

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

定義和用法

<xsl:apply-imports> 元素可應用來自導入樣式表中的模版規則。

導入樣式表中的模版規則的優先級要比主樣式表中的模版規則要低。 如果您希望使用導入樣式表中的某條模版規則,而不是主樣式表中的某條等價規則,就會用到<xsl:apply-imports> 元素。


語法

<xsl:apply-imports/>

屬性

實例

假設我們有一個名為"standard.xsl" 的樣式表,其中包含用於message 元素的模版規則:

<?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="message">
<h2><xsl:apply-templates/></h2>
</xsl:template>

</xsl:stylesheet>

另一個樣式表能夠導入"standard.xsl",並修改message 元素,如下所示:

<?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="standard.xsl"/>

<xsl:template match="message">
<div style="border:solid blue">
<xsl:apply-imports/>
</div>
</xsl:template>

</xsl:stylesheet>

結果將會把一條消息轉換到表單元素中:

<div style="border:solid blue"><h2>...</h2></div>


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