2014-01-22 34 views
0

我有這樣的一個模板:通價值爲模板名稱XSLT

<xsl:template name="TextInput"> 
    <div>TextInput type template called</div> 
</xsl:template> 

而且我有一個循環:

​​

在這ns:type對應於不同的名稱。在這種情況下,ns:type等於TextInput。但我可以有更多不同的類型。所以我正在嘗試爲每種類型創建不同的模板,以便根據類型調用模板。直接將ns:type傳入模板名稱不起作用我得到:"[FATAL]: Could not compile stylesheet"。無論如何,我可以做到這一點?將元素中的類型直接傳遞給模板名稱?

回答

2

在XSLT中執行動態分發的方法是使用xsl:apply-templates而不是xsl:call-template

更換

<xsl:template name="TextInput"> 
    <div>TextInput type template called</div> 
</xsl:template> 

通過

<xsl:template match="ns:type[.='TextInput']"> 
    <div>TextInput type template called</div> 
</xsl:template> 

並更換

<xsl:call-template name="ns:type"/> 

通過

<xsl:apply-templates select="ns:type"/>