2012-08-05 29 views
2

我有一個xslt樣式表,它的功能沒有問題。我需要將mode屬性添加到所有xsl:template元素。爲了向所有元素添加屬性並保持樣式表正常工作,我應該記住哪些事實。任何幫助表示讚賞。先謝謝你。將「mode」屬性添加到xslt樣式表中

回答

3

那麼它取決於樣式表和您想要使用的確切模式值,詳情請參閱http://www.w3.org/TR/xslt20/#modes

假設你有類似沒有模式屬性的模板,例如

<xsl:template match="foo"> 
    <bar> 
    <xsl:apply-templates/> 
    </bar> 
</xsl:template> 

,並要使用一定的模式,那麼你必須改變兩個xsl:template還有xsl:apply-templates例如

<xsl:template match="foo" mode="m1"> 
    <bar> 
    <xsl:apply-templates mode="m1"/> 
    </bar> 
</xsl:template> 

apply-templates你有不同的選項,但是,您可以使用

<xsl:template match="foo" mode="m1"> 
    <bar> 
    <xsl:apply-templates mode="#current"/> 
    </bar> 
</xsl:template> 

雖然與單模值是沒有區別的。

+0

非常感謝。但我添加了「模式」到所有我有xsl:template和xsl:template的地方。現在樣式表不能正常工作。我在所有地方應用了相同的模式名稱。我錯過了什麼嗎? – harsh 2012-08-05 11:53:00

+0

'我添加了「模式」所有我有xsl:template和xsl:template'的地方出錯了嗎?我試圖指出,您需要更改'xsl:template'以及'xsl:apply-templates'。如果你有一個具體的樣式表在嘗試添加模式後失敗,那麼最好(至少對我來說)幫助你向我們展示輸入,原始樣式表,新的樣式表,你想要的輸出和那個你得到。 – 2012-08-05 13:34:45

+0

我錯過了一個模板。非常感謝您的回答。 – harsh 2012-08-05 16:46:03