我可以在xsl中使用'and'运算符吗?

时间:2023-01-14 08:07:38

Simply can I execute the following in xsl?

我可以在xsl中执行以下操作吗?

 <xsl:for-each select="trip/instance[.!=''] and trip/result[.!='']">
 </xsl: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中使用select =“”时,它会改变我在每个内部使用的代码的选择器范围吗?

2 个解决方案

#1


7  

You can use 'and' in for-each loop, but not in the way you have mentioned (being not sure what exactly you want to achieve)

您可以在for-each循环中使用'and',但不能以您提到的方式使用(不确定您想要实现的目标)

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 ..

我假设您的要求类似于:1)您想要遍历Trip,其子实体(实例和结果)不为空,在这种情况下,您必须像这样写。

<xsl:for-each select="trip[instance!='' and result!='']>

if any one among instance and result are null, then your loop doesn't enter the element namely, trip.

如果实例和结果中的任何一个为null,那么你的循环不会进入元素,即trip。


2) You want to seek through each instanceandresult children inside parent trip whose values are not null. In this case you Don't need and ..

2)你想通过父旅行中的每个实例和结果寻找其值不为空的子项。在这种情况下,你不需要和..

<xsl:for-each select="trip/instance[.!=''] | trip/result[.!='']">

This will work.

这会奏效。

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" ..

现在回答你的Q ..用FOR-EACH循环你可以设置选择器的范围..例如:在情况(1)中,选择器的范围是“root_name // trip”和case(2)选择器的范围是“root_name // trip / instance”也是“root_name // trip / result”..

I hope, I understood your question correctly and answered it as understandable ..

我希望,我正确理解你的问题并回答它是可以理解的..

#2


6  

No, you cannot use and in the select attribute.

不,您不能在select属性中使用和。

You want to use the union operator: |, which behaves kind of like an and and kind of like an or, depending on how you think about it.

你想使用union运算符:|,它的行为类似于an和类似的或者,取决于你如何看待它。

It will give you a distinct list of both sets of nodes and will return them in the document order that it finds them(not all instance and then all result elements).

它将为您提供两个节点集的明确列表,并将按照它找到的文档顺序返回它们(不是所有实例,而是所有结果元素)。

 <xsl:for-each select="trip/instance[.!=''] | trip/result[.!='']">
 </xsl:for-each>

Inside the for-each the context will switch between each of the selected nodes during each iteration. You can access the current node with . or current().

在for-each内部,每次迭代期间,上下文将在每个所选节点之间切换。您可以使用访问当前节点。或当前()。

#1


7  

You can use 'and' in for-each loop, but not in the way you have mentioned (being not sure what exactly you want to achieve)

您可以在for-each循环中使用'and',但不能以您提到的方式使用(不确定您想要实现的目标)

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 ..

我假设您的要求类似于:1)您想要遍历Trip,其子实体(实例和结果)不为空,在这种情况下,您必须像这样写。

<xsl:for-each select="trip[instance!='' and result!='']>

if any one among instance and result are null, then your loop doesn't enter the element namely, trip.

如果实例和结果中的任何一个为null,那么你的循环不会进入元素,即trip。


2) You want to seek through each instanceandresult children inside parent trip whose values are not null. In this case you Don't need and ..

2)你想通过父旅行中的每个实例和结果寻找其值不为空的子项。在这种情况下,你不需要和..

<xsl:for-each select="trip/instance[.!=''] | trip/result[.!='']">

This will work.

这会奏效。

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" ..

现在回答你的Q ..用FOR-EACH循环你可以设置选择器的范围..例如:在情况(1)中,选择器的范围是“root_name // trip”和case(2)选择器的范围是“root_name // trip / instance”也是“root_name // trip / result”..

I hope, I understood your question correctly and answered it as understandable ..

我希望,我正确理解你的问题并回答它是可以理解的..

#2


6  

No, you cannot use and in the select attribute.

不,您不能在select属性中使用和。

You want to use the union operator: |, which behaves kind of like an and and kind of like an or, depending on how you think about it.

你想使用union运算符:|,它的行为类似于an和类似的或者,取决于你如何看待它。

It will give you a distinct list of both sets of nodes and will return them in the document order that it finds them(not all instance and then all result elements).

它将为您提供两个节点集的明确列表,并将按照它找到的文档顺序返回它们(不是所有实例,而是所有结果元素)。

 <xsl:for-each select="trip/instance[.!=''] | trip/result[.!='']">
 </xsl:for-each>

Inside the for-each the context will switch between each of the selected nodes during each iteration. You can access the current node with . or current().

在for-each内部,每次迭代期间,上下文将在每个所选节点之间切换。您可以使用访问当前节点。或当前()。