XSL - Does evaluating conditional expressions “shortcut”?

偶尔善良 提交于 2019-12-23 12:42:41

问题


Given an XSL 'If' statement:

<xsl:if test="a = 'some value' and b = 'another value'">

If a does not equal 'some value', is the value of b still checked? (As if the first test is false, the only outcome of the and is false.) This is what languages like C# do - I was wondering if the same goes in XSL. Does it depend on the engine/parser?


回答1:


Yes, it is called lazy-evaluation or short-circuiting, and xsl supports it. See: http://www.w3.org/TR/xpath#booleans

An and expression is evaluated by evaluating each operand and converting its value to a boolean as if by a call to the boolean function. The result is true if both values are true and false otherwise. The right operand is not evaluated if the left operand evaluates to false.




回答2:


Yes, this is depending on the implementation. But since XSLT is side-effect-free (as opposed to C# and other languages, where a function call chainging some state or even an assignment can be in the expression), this does not matter.



来源:https://stackoverflow.com/questions/1410057/xsl-does-evaluating-conditional-expressions-shortcut

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!