2015-02-23 43 views
0

我有下面的模板是XSL:申請模板選擇要在XSL調用不同的模板

<xsl:apply-templates 
        select="fpml:dataDocument/fpml:trade/fpml:swap/fpml:swapStream/fpml:payerPartyReference[starts-with(@href, 'PO')]" /> 

如上圖所示,這是工作的罰款「PO」現在我想使它成爲CPTY太所以我開發它,如..

<xsl:apply-templates 
        select="fpml:dataDocument/fpml:trade/fpml:swap/fpml:swapStream/fpml:payerPartyReference[starts-with(@href, 'CPTY')]" /> 

,但問題是,不能使用相同的名稱payerPartyReference可以請你指教一下是處理這個最好的方法有兩個seprate模板..

我在想什麼方法..

<xsl:if test="fpml:dataDocument/fpml:trade/fpml:swap/fpml:swapStream/fpml:payerPartyReference[starts-with(@href, 'PO')]"> 


    </xsl:if> 


    <xsl:if test="fpml:dataDocument/fpml:trade/fpml:swap/fpml:swapStream/fpml:payerPartyReference[starts-with(@href, 'CPTY')]"> 


    </xsl:if>  

回答

2

你說得對,你不能有兩個模板完全相同的匹配模式,但你可以有

<xsl:template match="fpml:payerPartyReference[starts-with(@href, 'PO')]"> 
    <!-- ... --> 
</xsl:template> 

<xsl:template match="fpml:payerPartyReference[starts-with(@href, 'CPTY')]"> 
    <!-- ... --> 
</xsl:template> 

有了這些單獨的模板你可能會發現你不需要拆分apply-templates。根據您的問題的確切細節,你可能會發現,你可以做一個

<xsl:apply-templates 
select="fpml:dataDocument/fpml:trade/fpml:swap/fpml:swapStream/fpml:payerPartyReference" /> 

,讓模板匹配處理條件行爲通過挑選合適的匹配模板爲每個目標節點。

+0

可能還需要一個來抑制內置模板,如果@ href可以以PO和CPTY之外的其他值開始 – Caleth 2015-02-23 13:15:13