Subject: [xsl] XSLT 2.0: Are arguments to functions evaluated eagerly or lazily? From: Justin Johansson <procode@xxxxxxxxxx> Date: Wed, 18 Jul 2007 11:31:29 +0900 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] search for aligned elemen, Abel Braaksma | Thread | RE: [xsl] XSLT 2.0: Are arguments t, Colin Adams |
[xsl] search for aligned elements, Rodrigo Segnini | Date | Re: [xsl] search for aligned elemen, Justin Johansson |
Month |