Evaluation of variables only if needed?
Added by Anonymous almost 17 years ago
Legacy ID: #4750933 Legacy Poster: juangamnik (juangamnik)
Hi, I read XSLT 2.0 3rd edition by Michael Kay (most of it) and it says, that a variable might be evaluated the first time it is used. So, this seems to be implementation specific. How does Saxon handle this? Background: I'm implementing a graph based transforming language for my diploma thesis, which can be generated to XSLT. The graphical approach depends on the delarative character of XSLT. There are many variables pointing at intermediate results, but only some of them are used for the result. The following (worst case) example shows, that it would be nice, if only one of the vairables is evaluated by Saxon. Simplified example of generated code: <xsl:variable name="test_1"> <!-- comlex sequence constructor> </xsl:variable> <!-- ... --> <xsl:variable name="test_n"> <!-- comlex sequence constructor> </xsl:variable> <xsl:choose <xsl:when test="some condition"> <xsl:copy-of select="$test_1"/> </xsl:when> <!-- ... --> <xsl:when test="some other condition"> <xsl:copy-of select="$test_n"/> </xsl:when> </xsl:choose> wfg, Jonny.
Replies (3)
Please register to reply
RE: Evaluation of variables only if needed? - Added by Anonymous almost 17 years ago
Legacy ID: #4750946 Legacy Poster: juangamnik (juangamnik)
I forgot a closing ">" in my example (<xsl:choose>)... though it is nevertheless no "running" code :)
RE: Evaluation of variables only if needed? - Added by Anonymous almost 17 years ago
Legacy ID: #4750985 Legacy Poster: Michael Kay (mhkay)
Yes, Saxon will generally not evaluate variables until the value is required. Also, Saxon will only evaluate that part of the value that is required. It's a bit more complex than that, though: for example if the variable can be evaluated at compile time, then it will be. Why are you using xsl:copy-of rather than xsl:sequence? I can't see offhand why you would need to make a copy. I suspect Saxon will probably do the copy even if it's unnecessary, though I would need to see the full stylesheet and the optimized execution plan to be sure.
RE: Evaluation of variables only if needed? - Added by Anonymous almost 17 years ago
Legacy ID: #4751061 Legacy Poster: juangamnik (juangamnik)
Hi, This was only a handwritten example, that should express, what I like to do... The temporary tree of the variable that is chosen by the xsl:when should be copied to the sequence constructor of the caller (which might be a result document). I'm not sure when to use xsl:sequence and when xsl:copy-of. Can I use xsl:sequence without copying nodes while I am in the scope of my stylesheet, but the "content"-sequence is copied to a result document, if it is used in a sequence constructor that produces output (main xsl:template or xsl:result-document)? Is that right?? wfg, Johannes Neubauer.
Please register to reply