XSLT 2.0: Are arguments to functions evaluated eagerly
Hello all, Being new to this list I trust I have the posting protocol right. I have a few questions which I'll post separately; hopefully they are interesting to the list and haven't been asked before. The first question is as much about XPath 2.0 as it is about XSLT 2.0, and I guess XQuery. Supposing you have a function that is passed two arguments, say, a condition argument, test, and an argument, value, that returns value if test is true and the empty sequence otherwise, is the value argument evaluated at the time of calling the function if the test argument is false? Is this processor implementation specific and/or are there any XSLT 2.0 processors which do evaluate lazily? The function's signature is: my:cond( $test as xs:boolean, $value as item()*) as item()* XSLT 2.0 implementation is: <xsl:function name="my:cond"> <xsl:param name="test"> <xsl:param name="value"> <xsl:sequence select="if ( $test) then $value else ()"/> </xsl:function> The rationale for this question is that, for brevity, I would prefer to write something like this <xsl:sequence select="my:cond( $validation-result, my:do-something-significant())"/> rather than <xsl:if test="$validation-result"> <xsl:sequence select="my:do-something-significant()"/> </xsl:if> It would be really nice to be able apply this idiom to a whole series of logical functions*** without suffering a huge performance hit. Then again, it might still be worthwhile for the sake of brevity and abstraction to employ the idiom anyway even if there is an eager evaluation performance penalty to be paid. A few comments on the last point, "Is code brevity in the face of a runtime performance hit worthwhile?" or "Is it more expensive to write code than it is to execute it?" would be welcome as well. *** Another example: <xsl:function name="my:cond-else"> <xsl:param name="test"> <xsl:param name="value"> <xsl:param name="value2"> <xsl:sequence select="if ( $test) then $value else $value2"/> </xsl:function> Thanks for contributions in advance, Justin Johansson Freelance XML / XSLT / XQuery Developer Australia procode(at)tpg(dot)com(dot)au
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format