|Re: [Acceleo] eInverse() and other functions [message #500585 is a reply to message #499713]
||Thu, 26 November 2009 21:28
| Sebastien Roy
Registered: November 2009
|Laurent Goubet wrote on Thu, 26 November 2009 04:52|
I am not that familiar with XSLT. Could you elaborate on the behavior
you'd like to see within Acceleo? We are not limited to what the
specification allows us to do; we are free to try and make the
specification evolve. If you see a nice way if providing such
functionalities, don't hesitate to report it to us .
Well, basically, the XSLT and M2T paradygm and goal are quite similar :
- They take as input an xml document (specialised for M2T)
- They parse this document and transform its elements in text elements as output.
- The process is absolutely static : there is no dynamic behaviour : no event, no time. The result of the process only depends on the initial inputs.
- You can navigate into the structure of the input document using a specific language : XPath for xslt, ocl for M2T.
The data beeing static, there is no need to dynamic modification of variable.
In xslt, the variable are mainly used as shortcuts. This prevents the developer to have too long or complex expressions and/or copy paste these long and complex expressions in different parts of the code. This is specifically usefull when the variables are used to gather a set of elements that will be used later in the code.
Actually, the variables are not evaluated when they are declared, but when they are used.
<xsl:variable name="foo" select="aVeryComplexExpression($templateParameter1, $currentNode)"/>
<xsl:variable name="result1" select="aTransformation($foo)"/>
<xsl:variable name="result2" select="anotherTransformation($foo)"/>
is similar to
<xsl:value-of select="aTransformation(aVeryComplexExpression($templateParameter1, $currentNode))"/>
<xsl:value-of select="anotherTransformation(aVeryComplexExpression($templateParameter1, $currentNode))"/>
The results are identical but the second expression is harder to write, to read and to maintain when the syntax is a little bit long.
In xslt, you can define variables anywhere in the code. That allow to define variables depending on the current node in a for-each loop, for instance.
(The equivalent in M2T of the "current-node" would be the iteration variable of the "for" loop).
The only drawback of not be able to modify variable is that the computations based on iterations for instance are sometimes more tedious. They have to be performed using recursive algorithms instead.
So, simply allowing to define new variable anywhere in the code would dramatically ease the use of complex expression without breaking the M2T paradigm.
Powered by FUDForum
. Page generated in 0.02253 seconds