XSLT <xsl:apply-imports> 元素
定義和用法
<xsl:apply-imports> 元素可應(yīng)用來(lái)自導(dǎo)入樣式表中的模版規(guī)則。
導(dǎo)入樣式表中的模版規(guī)則的優(yōu)先級(jí)要比主樣式表中的模版規(guī)則要低。如果您希望使用導(dǎo)入樣式表中的某條模版規(guī)則,而不是主樣式表中的某條等價(jià)規(guī)則,就會(huì)用到 <xsl:apply-imports> 元素。
語(yǔ)法
<xsl:apply-imports/>
屬性
None
實(shí)例
假設(shè)我們有一個(gè)名為 "standard.xsl" 的樣式表,其中包含用于 message 元素的模版規(guī)則:
<?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>
另一個(gè)樣式表能夠?qū)?"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>
結(jié)果是:將把一條消息轉(zhuǎn)換到格狀的元素中:
<div style="border:solid blue"><h2>...</h2></div>