Menu

#25 Another example (HibernateDAO from hbm.xml)

open
nobody
None
5
2005-08-23
2005-08-23
Anonymous
No

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:param
name="genDAO">net.sf.hiberdao.GenericHibernateDAO</xsl:param>
<xsl:template match="/hibernate-mapping">
<xsl:for-each select="class">
<![CDATA[public class ]]>
<xsl:value-of select="@name"/>
<![CDATA[DAO]]>
<xsl:value-of select="'&#10;'"/>
<![CDATA[ extends ]]>
<xsl:value-of select="$genDAO"/>
<![CDATA[<]]>
<xsl:value-of select="@name"/>
<xsl:value-of select="', '"/>
<xsl:value-of select="id/@type"/>
<![CDATA[> {]]>
<xsl:value-of select="'&#10;'"/>
<![CDATA[ public ]]>
<xsl:value-of select="@name"/>
<![CDATA[DAO() {
super(]]>
<xsl:value-of select="@name"/>
<![CDATA[.class, ]]>
<xsl:value-of select="id/@type"/>
<![CDATA[.class);
}
}
]]>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Discussion

  • Nobody/Anonymous

    Logged In: NO

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:str="http://exslt.org/strings"
    extension-element-prefixes="str">
    <xsl:output method="text" />
    <xsl:param
    name="genDAOlong">net.sf.gendao.GenericHibernateDAO</xsl:param>
    <xsl:param name="genDAO">GenericHibernateDAO</xsl:param>
    <xsl:template match="/hibernate-mapping">
    <xsl:for-each select="class">
    <xsl:value-of select="'package '"/>
    <xsl:for-each select="str:tokenize(@name, '.')">
    <xsl:if test="position() != last()">
    <xsl:value-of select="."/>
    <xsl:if test="position() != (last() - 1)">
    <xsl:value-of select="'.'"/>
    </xsl:if>
    <xsl:if test="position() = (last() - 1)">
    <xsl:value-of select="';'"/>
    <xsl:value-of select="'&#10;'" />
    </xsl:if>
    </xsl:if>
    </xsl:for-each>
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="'import
    net.sf.gendao.GenericHibernateDAO;'"/>
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="concat('import ', @name, ';')"/>
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="concat('import ',
    id/@type|composite-id/@class, ';')"/>
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="'&#10;'" />
    <xsl:variable name="class">
    <xsl:for-each select="str:tokenize(@name, '.')">
    <xsl:if test="position() = last()">
    <xsl:value-of select="."/>
    </xsl:if>
    </xsl:for-each>
    </xsl:variable>
    <xsl:variable name="idClass">
    <xsl:for-each
    select="str:tokenize(id/@type|composite-id/@class, '.')">
    <xsl:if test="position() = last()">
    <xsl:value-of select="."/>
    </xsl:if>
    </xsl:for-each>
    </xsl:variable>
    <xsl:value-of
    select="concat('public class ', $class, 'DAO')" />
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of
    select="concat(' extends ', $genDAO, '&lt;', $class, ',
    ', $idClass, '&gt; {')" />
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="concat(' public ', $class, 'DAO()
    {')" />
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of
    select="concat(' super(', $class, '.class, ',
    $idClass, '.class);')" />
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="' }'" />
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="'}'" />
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

     
  • Nobody/Anonymous

    Logged In: NO

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:str="http://exslt.org/strings"
    extension-element-prefixes="str">
    <xsl:output method="text" />
    <xsl:param
    name="genDAOlong">net.sf.gendao.GenericHibernateDAO</xsl:param>
    <xsl:param name="genDAO">GenericHibernateDAO</xsl:param>
    <xsl:template match="/hibernate-mapping">
    <xsl:for-each select="class">
    <xsl:variable name="class">
    <xsl:for-each select="str:tokenize(@name, '.')">
    <xsl:if test="position() = last()">
    <xsl:value-of select="."/>
    </xsl:if>
    </xsl:for-each>
    </xsl:variable>
    <xsl:variable name="idClass">
    <xsl:for-each
    select="str:tokenize(id/@type|composite-id/@class, '.')">
    <xsl:if test="position() = last()">
    <xsl:choose>
    <xsl:when test=". = 'long'">
    <xsl:value-of select="'Long'"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="."/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:if>
    </xsl:for-each>
    </xsl:variable>
    <xsl:variable name="idClassFull">
    <xsl:choose>
    <xsl:when test="id/@type|composite-id/@class =
    'long'">
    <xsl:value-of select="'java.lang.Long'"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of
    select="id/@type|composite-id/@class"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
    <xsl:variable name="package">
    <xsl:for-each select="str:tokenize(@name, '.')">
    <xsl:if test="position() != last()">
    <xsl:value-of select="."/>
    <xsl:if test="position() != (last() - 1)">
    <xsl:value-of select="'.'"/>
    </xsl:if>
    </xsl:if>
    </xsl:for-each>
    </xsl:variable>
    <xsl:value-of select="concat('package ', $package, ';')"/>
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="concat('import ',
    $genDAOlong, ';')"/>
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="concat('import ', @name, ';')"/>
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="concat('import ',
    $idClassFull, ';')"/>
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of
    select="concat('public class ', $class, 'DAO')" />
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of
    select="concat(' extends ', $genDAO, '&lt;', $class, ',
    ', $idClass, '&gt; {')" />
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="concat(' public ', $class, 'DAO()
    {')" />
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of
    select="concat(' super(', $class, '.class, ',
    $idClass, '.class);')" />
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="' }'" />
    <xsl:value-of select="'&#10;'" />
    <xsl:value-of select="'}'" />
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.