first stab at CDBI autogen
authormiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Mon, 6 Jun 2005 20:53:34 +0000 (20:53 +0000)
committermiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Mon, 6 Jun 2005 20:53:34 +0000 (20:53 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@331 9efc2488-bf62-4759-914b-345cdb29e865

examples/fieldmapper2cdbi.xsl [new file with mode: 0644]

diff --git a/examples/fieldmapper2cdbi.xsl b/examples/fieldmapper2cdbi.xsl
new file mode 100644 (file)
index 0000000..f6ad904
--- /dev/null
@@ -0,0 +1,79 @@
+<xsl:stylesheet
+       version='1.0'
+       xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
+       xmlns:opensrf="http://opensrf.org/xmlns/opensrf"
+       xmlns:cdbi="http://opensrf.org/xmlns/opensrf/cdbi"
+       xmlns:database="http://opensrf.org/xmlns/opensrf/database"
+       xmlns:perl="http://opensrf.org/xmlns/opensrf/perl"
+       xmlns:javascript="http://opensrf.org/xmlns/opensrf/javascript"
+       xmlns:c="http://opensrf.org/xmlns/opensrf/c">
+       <xsl:output method="text" />
+       <xsl:strip-space elements="*"/>
+
+       <xsl:template match="/">
+               <xsl:apply-templates select="opensrf:fieldmapper/opensrf:classes"/>
+1;
+       </xsl:template>
+
+
+       <!-- sub-templates -->
+       <xsl:template match="opensrf:classes">
+               <xsl:for-each select="opensrf:class">
+                       <xsl:sort select="@id"/>
+                       <xsl:apply-templates select="."/>
+               </xsl:for-each>
+               <xsl:apply-templates select="opensrf:class/opensrf:links/opensrf:link[@type='has_a']"/>
+               <xsl:apply-templates select="opensrf:class/opensrf:links/opensrf:link[@type='has_many']"/>
+       </xsl:template>
+
+
+       
+       <xsl:template match="opensrf:class">
+               #-------------------------------------------------------------------------------
+               # <xsl:value-of select="$driver"/> Class definition for "<xsl:value-of select="@id"/>" (<xsl:value-of select="cdbi:class"/>)
+               #-------------------------------------------------------------------------------
+               package <xsl:value-of select="@cdbi:class"/>;
+               use base '<xsl:value-of select="cdbi:superclass"/>';
+
+               __PACKAGE__->table("<xsl:value-of select="database:table[@rdbms=$driver]/database:name"/>");
+               <xsl:if test="database:table[@rdbms=$driver]/database:sequence">
+                       __PACKCAGE__->sequence("<xsl:value-of select="database:table[@rdbms=$driver]/database:sequence"/>");
+               </xsl:if>
+
+               __PACKAGE__->columns(Primary => <xsl:apply-templates select="opensrf:fields/opensrf:field[@database:primary='true']"/>);
+               <xsl:if test="opensrf:fields/opensrf:field[@database:required='true' and not(@database:primary='true')]">
+                       __PACKAGE__->columns(
+                               Essential => <xsl:apply-templates
+                                               select="opensrf:fields/opensrf:field[@database:required='true' and not(@database:primary='true')]"/>
+                       );
+               </xsl:if>
+               <xsl:if test="opensrf:fields/opensrf:field[not(@database:required='true') and not(@database:primary='true')]">
+                       __PACKAGE__->columns(
+                               Others => <xsl:apply-templates
+                                               select="opensrf:fields/opensrf:field[not(@database:required='true') and not(@database:primary='true')]"/>
+                       );
+               </xsl:if>
+       </xsl:template>
+
+
+
+       <xsl:template match="database:table">
+       </xsl:template>
+
+
+
+       <xsl:template match="opensrf:field">
+               '<xsl:value-of select='@name'/>',
+       </xsl:template>
+
+
+
+       <xsl:template match="opensrf:link">
+               <xsl:variable name='source' select='@source'/>
+               <xsl:value-of select="../../@cdbi:class"/>-><xsl:value-of select="@type"/>(
+                       <xsl:value-of select="@field"/> => '<xsl:value-of select="//*[@id=$source]/@cdbi:class"/>'
+               );
+
+       </xsl:template>
+</xsl:stylesheet>
+