Author: hibou
Date: Sun Feb 21 23:06:53 2010
New Revision: 912435

URL: http://svn.apache.org/viewvc?rev=912435&view=rev
Log:
Try to convert antcontrib's if into the groovy one with some heuristics

Modified:
    ant/sandbox/groovyfront/xml2groovy.xsl

Modified: ant/sandbox/groovyfront/xml2groovy.xsl
URL: 
http://svn.apache.org/viewvc/ant/sandbox/groovyfront/xml2groovy.xsl?rev=912435&r1=912434&r2=912435&view=diff
==============================================================================
--- ant/sandbox/groovyfront/xml2groovy.xsl (original)
+++ ant/sandbox/groovyfront/xml2groovy.xsl Sun Feb 21 23:06:53 2010
@@ -58,13 +58,43 @@
         <apply-templates select="child::node()" />
     </template>
 
+    <!-- heuristic about antcontrib's if -->
+    <template match="*[contains(namespace-uri(.), 'antcontrib') and 
local-name() = 'if']">
+        <text>if (</text>
+        <apply-templates select="*[position() = 1]" mode="condition" />
+        <text>) {</text>
+        <apply-templates select="then/child::node()" />
+        <if test="count(else/child::node()) != 0">
+            <text>} else {</text>
+            <apply-templates select="else/child::node()" />
+        </if>
+        <text>}</text>
+    </template>
+
+    <template match="*[local-name() = 'istrue' and starts-with(@value, '{') 
and not (starts-with(@value, '.') )]" mode="condition">
+        <text>&quot;</text><value-of select="@value" /><text>&quot;</text>
+    </template>
+
+    <template match="*[local-name() = 'isfalse' and starts-with(@value, '{') 
and not (starts-with(@value, '.') )]" mode="condition">
+        <text>!&quot;</text><value-of select="@value" /><text>&quot;</text>
+    </template>
+
+    <template match="*[local-name() = 'not']" mode="condition">
+        <text>!</text><apply-templates select="child::*" />
+    </template>
+
+    <template match="*" mode="condition">
+        <apply-templates select="." />
+    </template>
+
     <!-- generic xml to groovy transformer -->
     <template match="*">
 
         <!-- if there is some namespace, append the use of the grooyns -->
         <variable name="nsPrefix" select="substring-before(name(), ':')" />
         <if test="string-length($nsPrefix) != 0">
-            <value-of select="$nsPrefix" /><text>.</text>
+            <value-of select="$nsPrefix" />
+            <text>.</text>
         </if>
 
         <!-- actual element / function name -->
@@ -112,12 +142,12 @@
                     <text>'</text>
                 </otherwise>
             </choose>
-        </if>        
+        </if>
 
         <text>)</text>
 
         <!-- process the children by recursively -->
-        <if test="count(child::node()) != 0">
+        <if test="count(child::*) != 0">
             <text> {</text>
             <apply-templates select="child::node()" />
             <text>}</text>


Reply via email to