问题描述
我可以在xsl中执行以下命令吗?
Simply can I execute the following in xsl?
<xsl:for-each select="trip/instance[.!=''] and trip/result[.!='']">
</xsl:for-each>
问:当我在for-each中使用select ="时,是否会更改我在for-each中使用的代码的选择器范围?
Q: When I use select="" in for-each does it change the scope of my selector for the code I use inside for-each?
推荐答案
您可以在for-each循环中使用"and",但不能采用您提到的方式(不确定要实现的目标是什么) )
我认为您的要求可能是
1)您要遍历两个子实体均为(instance
和result
)不为null的Trip
,在这种情况下,您必须这样写..
I assume your requirements something like, either
1) You want to loop through Trip
whose both child entities are (instance
and result
) not null,In this case you have to write like this ..
<xsl:for-each select="trip[instance!='' and result!='']>
如果实例和结果中的任何一个为null,那么您的循环就不会输入跳闸元素.
if any one among instance and result are null, then your loop doesn't enter the element namely, trip.
2)您想遍历其值不为null的父级trip
中的每个instance
和result
子级.在这种情况下,您不需要and
..
2) You want to seek through each instance
andresult
children inside parent trip
whose values are not null. In this case you Don't need and
..
<xsl:for-each select="trip/instance[.!=''] | trip/result[.!='']">
这将起作用.
现在回答您的问题..
使用FOR-EACH循环,您可以设置选择器..的范围
例如:在情况(1)中,选择器的范围是"root_name//trip
",在情况(2)中,选择器的范围是"root_name//trip/instance
"也是"root_name//trip/result
" ..
Now answer to your Q ..
with FOR-EACH loop you can set the scope of selector ..
for-example:In case (1), scope of selector was "root_name//trip
" and in case (2) scope of selector was "root_name//trip/instance
" also "root_name//trip/result
" ..
希望我能正确理解您的问题,并回答为可以理解的..
这篇关于我可以在xsl for-each中使用'and'运算符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!