XSLT <xsl:apply-imports> 元素

定義和用法

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

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

語法

<xsl:apply-imports/>

屬性

None

實例

假設我們有一個名為 "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>