Skip to content

Instantly share code, notes, and snippets.

@SlyNet
Created April 25, 2013 08:55
Show Gist options
  • Save SlyNet/5458430 to your computer and use it in GitHub Desktop.
Save SlyNet/5458430 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:string="http://symphony-cms.com/functions"
xmlns:func="http://exslt.org/functions"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
extension-element-prefixes="func">
<xsl:output method="text"/>
<xsl:variable name="accessDict">
<accesses>
<access key="property" value="Accessor.Property"/>
</accesses>
</xsl:variable>
<xsl:key name="accessByName" match="access" use="string(@key)"/>
<xsl:variable name="cascadeDict">
<cascades>
<cascade key="all-delete-orphan" value="Cascade.DeleteOrphans" />
<cascade key="all" value="Cascade.All" />
</cascades>
</xsl:variable>
<xsl:template match="map">
<xsl:for-each select="class">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>
<xsl:template match="class">
<xsl:variable name="fullClassName" select="tokenize(@name, ',')[1]"/>
<xsl:variable name="className" select="tokenize($fullClassName, '\.')[last()]"/>
public class <xsl:value-of select="$className"/>Map : ClassMapping&lt;<xsl:value-of select="$className"/>&gt;
{
public <xsl:value-of select="$className"/>Map()
{
<xsl:for-each select="child::*">
<xsl:apply-templates select="."/>
</xsl:for-each>
}
}
</xsl:template>
<xsl:template match="property">
<xsl:param name="prefix"></xsl:param>
<xsl:value-of select="$prefix"/>Property(x => x.<xsl:value-of select="@name"/>, pm => {
pm.Column(&quot;<xsl:value-of select="column/@name"/>&quot;);
<xsl:if test="column/@not-null">
pm.NotNullable(<xsl:value-of select="column/@not-null"/>);
</xsl:if>
});
</xsl:template>
<xsl:template match="component">
Component(c => c.<xsl:value-of select="@name"/>, cm => {
<xsl:for-each select="child::*">
<xsl:apply-templates select=".">
<xsl:with-param name="prefix">cm.</xsl:with-param>
</xsl:apply-templates>
</xsl:for-each>
});
</xsl:template>
<xsl:template match="many-to-one">
ManyToOne(x => x.<xsl:value-of select="@name"/>, mto => {
mto.Column(&quot;<xsl:value-of select="@column"/>&quot;);
<xsl:if test="@not-null">
mto.NotNullable(<xsl:value-of select="@not-null"/>);
</xsl:if>
});
</xsl:template>
<xsl:template match="bag">
Bag(x => x.<xsl:value-of select="@name"/>, bm => {
bm.Table(&quot;<xsl:value-of select="@table"/>&quot;);
<xsl:if test="@lazy">
bm.Lazy(CollectionLazy.Lazy);
</xsl:if>
<xsl:if test="key/@column">
bm.Key(km => km.Column(&quot;<xsl:value-of select="key/@column"/>&quot;));
</xsl:if>
<xsl:if test="@inverse">
bm.Inverse(<xsl:value-of select="@inverse"/>);
</xsl:if>
bm.Access(<xsl:value-of select="key('accessByName', ./@access ,$accessDict)/@value"/>); <!-- todo: implement-->
}, colMap => {
<xsl:choose>
<xsl:when test="count(./many-to-many) &gt; 0">
colMap.ManyToMany(mtm => {
mtm.Column(&quot;<xsl:value-of select="many-to-many/@column"/>&quot;);
}
</xsl:when>
<xsl:when test="count(./one-to-many) &gt; 0">
colMap.OneToMany();
</xsl:when>
</xsl:choose>
}));
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment