xsl:如何在“匹配"中使用参数? [英] xsl: how to use parameter inside "match"?

查看:33
本文介绍了xsl:如何在“匹配"中使用参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 xsl 有一个参数

My xsl has a parameter

<xsl:param name="halfPath" select="'halfPath'"/>

我想在比赛中使用它

<xsl:template match="Element[@at1='value1' and not(@at2='{$halfPath}/another/half/of/the/path')]"/>

但这行不通.我猜''里面不能使用参数.如何解决/解决这个问题?

But this doesn't work. I guess a can not use parameters inside ''. How to fix/workaround that?

推荐答案

好吧,你可以在模板中使用条件指令:

Well, you could use a conditional instruction inside the template:

<xsl:template match="Element[@at1='value1']">
  <xsl:if test="not(@at2=concat($halfPath,'/another/half/of/the/path'))">
    .. do something
  </xsl:if>
</xsl:template>

你只需要知道这个模板将处理满足第一个条件的所有元素.如果您有一个不同的模板来处理与第一个匹配但不与第二个匹配的元素,则使用 <xsl:choose>,并将另一个模板的主体放在 <xsl:otherwise> 块.

You just need to be aware that this template will handle all elements that satisfy the first condition. If you have a different template that handles elements that match the first, but not the second, then use an <xsl:choose>, and put the other template's body in the <xsl:otherwise> block.

或者,如果您可以切换到 XSLT2 处理器,XSLT2 可以按原样处理它.

Or, XSLT2 can handle it as is if you can switch to an XSLT2 processor.

这篇关于xsl:如何在“匹配"中使用参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆