我有以下模板,即xsl:apply template
<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您能告诉我处理这个问题的最佳方法是什么吗?
我在想什么方法是..
<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> 发布于 2015-02-23 19:21:44
您说得对,您不能让两个模板具有完全相同的匹配模式,但您可以
<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" />并且让模板匹配器通过为每个目标节点挑选适当的匹配模板来处理条件行为。
https://stackoverflow.com/questions/28672511
复制相似问题