]> git.evergreen-ils.org Git - OpenSRF.git/blob - examples/fieldmapper2cdbi.xsl
Patch from Scott McKellar:
[OpenSRF.git] / examples / fieldmapper2cdbi.xsl
1 <xsl:stylesheet
2         version='1.0'
3         xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
4         xmlns:opensrf="http://opensrf.org/xmlns/opensrf"
5         xmlns:cdbi="http://opensrf.org/xmlns/opensrf/cdbi"
6         xmlns:database="http://opensrf.org/xmlns/opensrf/database"
7         xmlns:perl="http://opensrf.org/xmlns/opensrf/perl"
8         xmlns:javascript="http://opensrf.org/xmlns/opensrf/javascript"
9         xmlns:c="http://opensrf.org/xmlns/opensrf/c">
10         <xsl:output method="text" />
11         <xsl:strip-space elements="*"/>
12
13         <xsl:template match="/">
14                 <xsl:apply-templates select="opensrf:fieldmapper/opensrf:classes"/>
15 1;
16         </xsl:template>
17
18
19         <!-- sub-templates -->
20         <xsl:template match="opensrf:classes">
21                 <xsl:for-each select="opensrf:class">
22                         <xsl:sort select="@id"/>
23                         <xsl:apply-templates select="."/>
24                 </xsl:for-each>
25                 <xsl:apply-templates select="opensrf:class/opensrf:links/opensrf:link[@type='has_a']"/>
26                 <xsl:apply-templates select="opensrf:class/opensrf:links/opensrf:link[@type='has_many']"/>
27         </xsl:template>
28
29
30         
31         <xsl:template match="opensrf:class">
32                 #-------------------------------------------------------------------------------
33                 # <xsl:value-of select="$driver"/> Class definition for "<xsl:value-of select="@id"/>" (<xsl:value-of select="cdbi:class"/>)
34                 #-------------------------------------------------------------------------------
35                 package <xsl:value-of select="@cdbi:class"/>;
36                 use base '<xsl:value-of select="cdbi:superclass"/>';
37
38                 __PACKAGE__->table("<xsl:value-of select="database:table[@rdbms=$driver]/database:name"/>");
39                 <xsl:if test="database:table[@rdbms=$driver]/database:sequence">
40                         __PACKCAGE__->sequence("<xsl:value-of select="database:table[@rdbms=$driver]/database:sequence"/>");
41                 </xsl:if>
42
43                 __PACKAGE__->columns(Primary => <xsl:apply-templates select="opensrf:fields/opensrf:field[@database:primary='true']"/>);
44                 <xsl:if test="opensrf:fields/opensrf:field[@database:required='true' and not(@database:primary='true')]">
45                         __PACKAGE__->columns(
46                                 Essential => <xsl:apply-templates
47                                                 select="opensrf:fields/opensrf:field[@database:required='true' and not(@database:primary='true')]"/>
48                         );
49                 </xsl:if>
50                 <xsl:if test="opensrf:fields/opensrf:field[not(@database:required='true') and not(@database:primary='true')]">
51                         __PACKAGE__->columns(
52                                 Others => <xsl:apply-templates
53                                                 select="opensrf:fields/opensrf:field[not(@database:required='true') and not(@database:primary='true')]"/>
54                         );
55                 </xsl:if>
56         </xsl:template>
57
58
59
60         <xsl:template match="database:table">
61         </xsl:template>
62
63
64
65         <xsl:template match="opensrf:field">
66                 '<xsl:value-of select='@name'/>',
67         </xsl:template>
68
69
70
71         <xsl:template match="opensrf:link">
72                 <xsl:variable name='source' select='@source'/>
73                 <xsl:value-of select="../../@cdbi:class"/>-><xsl:value-of select="@type"/>(
74                         <xsl:value-of select="@field"/> => '<xsl:value-of select="//*[@id=$source]/@cdbi:class"/>'
75                 );
76
77         </xsl:template>
78 </xsl:stylesheet>
79