2015-02-23 79 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