Mercurial > pub > ModelGenerator
diff xslt/model.xsl @ 3:437127ab6a12
non-working version
separate common model templates from csharp templates, plans to support complex
primary and foreign keys
author | cin |
---|---|
date | Wed, 28 Feb 2018 02:10:29 +0300 |
parents | 035de8b7b18e |
children | d240adc2ac70 |
line wrap: on
line diff
--- a/xslt/model.xsl Sun Feb 25 17:12:33 2018 +0300 +++ b/xslt/model.xsl Wed Feb 28 02:10:29 2018 +0300 @@ -28,16 +28,7 @@ <xsl:apply-templates mode="document" /> </xsl:template> - <!-- generate code for primary package --> - <xsl:template match="m:package[@primary='true' and @clr:namespace]" mode="document"> - <cs:namespace name="{@clr:namespace}"> - <xsl:apply-templates mode="document" /> - </cs:namespace> - </xsl:template> - - <xsl:template match="m:package[@primary='true']" mode="document"> - <xsl:apply-templates mode="document" /> - </xsl:template> + <!-- member resolution traits --> @@ -163,8 +154,6 @@ - <!-- primary key --> - <!-- Resolves primaryKey information for the given type name. @returns m:primaryKey node copy with additional attribute @declaringType which points to the type where this primaryKey @@ -178,134 +167,28 @@ </xsl:call-template> </xsl:template> - <!-- --> - <xsl:template name="getKeyType"> - <xsl:param name="type" /> - <xsl:variable name="otherKey"> - <xsl:call-template name="getKey"> - <xsl:with-param name="type" select="$type" /> - </xsl:call-template> - </xsl:variable> - <xsl:apply-templates select="exsl:node-set($otherKey)/m:primaryKey" mode="property-type"/> - </xsl:template> + <xsl:template match="*|text()" mode="process-member"/> - <xsl:template name="getKeyName"> - <xsl:param name="type" /> - <xsl:variable name="otherKey"> - <xsl:call-template name="getKey"> - <xsl:with-param name="type" select="$type" /> - </xsl:call-template> - </xsl:variable> - <xsl:apply-templates select="exsl:node-set($otherKey)/m:primaryKey" mode="property-name"/> - </xsl:template> - - <!-- internal. applied to the entity with a primaryKey node --> - <xsl:template match="m:entity[m:primaryKey]" mode="resolvePK"> - <xsl:apply-templates select="m:primaryKey" mode="resolvePK" /> - </xsl:template> - - <!-- - This template formats the result of 'resolvePk' template, - override this template to extend returned metadata, beware that - other templates rely on the resulting format of this template. - --> - <xsl:template match="m:primaryKey" mode="resolvePK"> - <xsl:copy> - <xsl:copy-of select="@*" /> - <xsl:attribute name="declaringType"><xsl:value-of select="../@name" /></xsl:attribute> - <xsl:copy-of select="*" /> - </xsl:copy> - </xsl:template> - - <!-- internal, used to traverse the hierarchy --> - <xsl:template match="m:entity" mode="resolvePK"> - <xsl:apply-templates select="m:extends" mode="resolvePK" /> - </xsl:template> - - <!-- internal, used to traverse the hierarchy --> - <xsl:template match="m:extends" mode="resolvePK"> - <xsl:apply-templates select="key('type', @type)" - mode="resolvePK" /> - </xsl:template> - - <!-- resolves CLR type for the given type --> - <xsl:template name="getClrType"> - <xsl:param name="type" /> - <xsl:param name="typeArgs" select="/.." /> - <!-- <t:trace msg="resolveClrType {$type}"/> --> - <xsl:for-each select="$module"> - <xsl:apply-templates select="key('type', $type)" - mode="clr-type"> - <xsl:with-param name="typeArgs" select="$typeArgs"/> - </xsl:apply-templates> - </xsl:for-each> + <xsl:template match="m:hasA" mode="process-member"> + <xsl:apply-templates mode="process-member"/> </xsl:template> - <!-- CLR type construction --> - <xsl:template match="*" mode="clr-type" /> - - <xsl:template match="m:type[clr:type]" mode="clr-type"> - <xsl:param name="typeArgs" select="clr:type/*" /> - <xsl:apply-templates select="clr:type" mode="clr-type"> - <xsl:with-param name="typeArgs" select="$typeArgs" /> - </xsl:apply-templates> - </xsl:template> - - <xsl:template match="m:entity" mode="clr-type"> - <cs:type name="{@clr:name | @name[not(../@clr:name)]}" namespace="{ancestor::*[@clr:namespace]/@clr:namespace}" /> + <xsl:template match="m:hasA[@type]/m:thisKey" mode="process-member"> + <xsl:variable name="foreignPrimaryKey"> + <xsl:call-template name="getPrimaryKey"> + <xsl:with-param name="type" select="../@type"/> + </xsl:call-template> + </xsl:variable> + <m:property type="{exsl:node-set($foreignPrimaryKey)[1]/@type}"> + <xsl:copy-of select="@*"/> + </m:property> </xsl:template> - <xsl:template match="clr:type" mode="clr-type"> - <xsl:apply-templates mode="clr-type"/> - </xsl:template> - - <xsl:template match="clr:type[@ref]" mode="clr-type"> - <xsl:param name="typeArgs" select="*" /> - <xsl:call-template name="getClrType"> - <xsl:with-param name="type" select="@ref" /> - <xsl:with-param name="typeArgs" select="$typeArgs" /> - </xsl:call-template> - </xsl:template> - - <xsl:template match="clr:type[@cs:name or @name]" mode="clr-type"> - <xsl:param name="typeArgs" select="*" /> - <xsl:variable name="ns" - select="@cs:namespace | @namespace[not(../@cs:namespace)]" /> - <cs:type name="{@cs:name | @name[not(../@cs:name)]}"> - <xsl:if test="$ns"> - <xsl:attribute name="namespace"><xsl:value-of select="$ns" /></xsl:attribute> - </xsl:if> - <xsl:copy-of select="@struct"/> - - <xsl:apply-templates select="$typeArgs | *[not($typeArgs)]" - mode="clr-type" /> - </cs:type> - </xsl:template> - - <xsl:template match="clr:arrayOf[@type]" mode="clr-type"> - <xsl:param name="typeArgs" select="*" /> - <cs:array> - <xsl:call-template name="getClrType"> - <xsl:with-param name="type" select="@type" /> - <xsl:with-param name="typeArgs" select="$typeArgs" /> - </xsl:call-template> - </cs:array> - </xsl:template> - - <xsl:template match="clr:arrayOf[@cs:name or @name]" mode="clr-type"> - <xsl:param name="typeArgs" select="*" /> - <xsl:variable name="ns" - select="@cs:namespace | @namespace[not(../@cs:namespace)]" /> - <cs:array> - <cs:type name="{@cs:name | @name[not(../@cs:name)]}"> - <xsl:if test="$ns"> - <xsl:attribute name="namespace"><xsl:value-of - select="$ns" /></xsl:attribute> - </xsl:if> - <xsl:apply-templates select="$typeArgs | *[not($typeArgs)]" - mode="clr-type" /> - </cs:type> - </cs:array> + <xsl:template match="m:primaryKey" mode="process-member"> + <m:property> + <xsl:copy-of select="@*"/> + <xsl:copy-of select="*"/> + </m:property> </xsl:template>