[rules-users] xslt for converting rule XML from drools 2 to jboss rule 4

Mark Proctor mproctor at codehaus.org
Wed Dec 19 12:59:49 EST 2007


arina he wrote:
> I was scraping internet for one xslt when I was converting drools 2 to 
> jboss rule 4, but couldn't find one,
did you read this?
http://wiki.jboss.org/wiki/Wiki.jsp?page=Drools2Migration
>  
> so I rolled up sleeves and created one by myself, put up here in case 
> anyone need it too.
How complete is it? Do you have any unit tests? If so we should add this 
as a contrib project for other users.
>  
> welcome comments.
>  
> Arina.
Keep up the good work :)
>  
>  
>
> <?
>
> xml version="1.0" encoding="UTF-8"?>
>
> <
>
> xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs 
> ="http://www.w3.org/2001/XMLSchema" xmlns:fn= 
> "http://www.w3.org/2005/xpath-functions" xmlns:java= 
> "http://drools.org/semantics/java" > <xsl:output method="xml" 
> version="1.0" indent= "yes" omit-xml-declaration="yes"/> <xsl:template 
> match="/" > <package name="com.sample "> <global identifier="doc" 
> type="Document" /> <xsl:apply-templates /> </package> </xsl:template> 
> <xsl:template name="javaimport" match="java:import"> <import 
> name="{.}" /> </xsl:template> <xsl:template name="javaFunction" 
> match="java:functions"> <xsl:if test="contains(.,'public')" > 
> <xsl:call-template name= "separate"> <xsl:with-param name="str" 
> select="substring-after(.,'public ')" /> </xsl:call-template> 
> </xsl:if> </xsl:template> <xsl:template name="separate" > <xsl:param 
> name="str" /> <xsl:choose> <xsl:when test="contains($str,'public')" > 
> <xsl:call-template name= "drlFn"> <xsl:with-param name="fnBody" 
> select="substring-before($str,'public')" /> </xsl:call-template> 
> <xsl:call-template name= "separate"> <xsl:with-param name="str" 
> select="substring-after($str,'public ')" /> </xsl:call-template> 
> </xsl:when> <xsl:otherwise> <xsl:call-template name= "drlFn"> 
> <xsl:with-param name="fnBody" select="$str" /> </xsl:call-template> 
> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template 
> name="drlFn" > <xsl:param name="fnBody" /> <function 
> name="{substring-before(substring-after($fnBody,' '),'(')}" 
> return-type="{substring-before($fnBody,' ')}"> <xsl:if 
> test="normalize-space(substring-before(substring-after($fnBody,'(' 
> ),')' ))!=''" > <xsl:call-template name= "params"> <xsl:with-param 
> name="paramStr" 
> select="normalize-space(substring-before(substring-after($fnBody,'(' 
> ),')' ))" /> </xsl:call-template> </xsl:if> <body> <xsl:call-template 
> name= "bdy"> <xsl:with-param name="bdyStr" 
> select="substring-after($fnBody,'{' )" /> </xsl:call-template> </body> 
> </function> </xsl:template> <xsl:template name="bdy" > <xsl:param 
> name="bdyStr" /> <xsl:value-of select="substring-before($bdyStr,'}')" 
> /> <xsl:if test="contains(substring-after($bdyStr,'}'),'}')" >
>
> }
>
> <xsl:call-template name= "bdy"> <xsl:with-param name="bdyStr" 
> select="substring-after($bdyStr,'}')" /> </xsl:call-template> 
> </xsl:if> </xsl:template> <xsl:template name="params" > <xsl:param 
> name="paramStr" /> <xsl:choose> <xsl:when 
> test="contains($paramStr,',')" > <xsl:call-template name= 
> "buildIdentifier"> <xsl:with-param name="tpy" 
> select="substring-before($paramStr,' ')" /> <xsl:with-param name="idt" 
> select="substring-after(substring-before($paramStr,','),' ')" /> 
> </xsl:call-template> <xsl:call-template name= "params"> 
> <xsl:with-param name="paramStr" 
> select="normalize-space(substring-after($paramStr,','))"/> 
> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template 
> name= "buildIdentifier"> <xsl:with-param name="tpy" 
> select="substring-before($paramStr,' ')" /> <xsl:with-param name="idt" 
> select="substring-after($paramStr,' ')" /> </xsl:call-template> 
> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template 
> name="buildIdentifier" > <xsl:param name="tpy" /> <xsl:param 
> name="idt" /> <parameter identifier="{$idt}" type="{$tpy}" /> 
> </xsl:template> <xsl:template name="rules" match="rule" > <rule 
> name="{@name}" > <xsl:if test="java:condition" > <lhs> 
> <and-constraint-connective> <xsl:for-each select="java:condition" > 
> <eval><xsl:value-of select="normalize-space(.)" 
> disable-output-escaping="no" /></eval> </xsl:for-each> 
> </and-constraint-connective> </lhs> </xsl:if> <xsl:for-each 
> select="java:consequence" > <rhs> <xsl:value-of select="." /> </rhs> 
> </xsl:for-each> </rule> </xsl:template>
>
> </
>
> xsl:stylesheet>
> ------------------------------------------------------------------------
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20071219/fd77e38c/attachment.html 


More information about the rules-users mailing list