Author: hibou
Date: Sun Feb 21 23:30:25 2010
New Revision: 912442
URL: http://svn.apache.org/viewvc?rev=912442&view=rev
Log:
Add condition task transformation into groovy's if-then-else
Modified:
ant/sandbox/groovyfront/xml2groovy.xsl
Modified: ant/sandbox/groovyfront/xml2groovy.xsl
URL:
http://svn.apache.org/viewvc/ant/sandbox/groovyfront/xml2groovy.xsl?rev=912442&r1=912441&r2=912442&view=diff
==============================================================================
--- ant/sandbox/groovyfront/xml2groovy.xsl (original)
+++ ant/sandbox/groovyfront/xml2groovy.xsl Sun Feb 21 23:30:25 2010
@@ -71,11 +71,33 @@
<text>}</text>
</template>
- <template match="*[local-name() = 'istrue' and starts-with(@value, '{')
and not (starts-with(@value, '.') )]" mode="condition">
+ <template match="*[local-name() = 'condition' and @property]">
+ <text>if (</text>
+ <apply-templates select="child::*" mode="condition" />
+ <text>) {
+</text>
+ <value-of select="@property" />
+ <!-- TODO handle the case of a property with a dot -->
+ <text> = "</text><value-of select="@value" /><text>"
+</text>
+ <if test="@else">
+ <text>} else {
+</text>
+ <value-of select="@property" />
+ <!-- TODO handle the case of a property with a dot -->
+ <text> = "</text><value-of select="@else" /><text>"
+</text>
+ </if>
+ <text>}</text>
+ </template>
+
+ <template match="*[local-name() = 'istrue']" mode="condition">
+ <!-- TODO handle the case of a property with a dot -->
<text>"</text><value-of select="@value" /><text>"</text>
</template>
- <template match="*[local-name() = 'isfalse' and starts-with(@value, '{')
and not (starts-with(@value, '.') )]" mode="condition">
+ <template match="*[local-name() = 'isfalse']" mode="condition">
+ <!-- TODO handle the case of a property with a dot -->
<text>!"</text><value-of select="@value" /><text>"</text>
</template>
@@ -83,6 +105,24 @@
<text>!</text><apply-templates select="child::*" />
</template>
+ <template match="*[local-name() = 'and']" mode="condition">
+ <for-each select="*">
+ <apply-templates select="." mode="condition" />
+ <if test="position() != last()">
+ <text> && </text>
+ </if>
+ </for-each>
+ </template>
+
+ <template match="*[local-name() = 'or']" mode="condition">
+ <for-each select="*">
+ <apply-templates select="." mode="condition" />
+ <if test="position() != last()">
+ <text> || </text>
+ </if>
+ </for-each>
+ </template>
+
<template match="*" mode="condition">
<apply-templates select="." />
</template>