Ambrosia

 view release on metacpan or  search on metacpan

share/Templates/db2xml.xsl  view on Meta::CPAN

		xmlns="app://Ambrosia/EntityDataModel/2011/V1"
		>

<xsl:output method="xml" indent="yes" encoding="utf-8" />
<xsl:include href="incName.xsl" />
<xsl:include href="incTypes.xsl" />

<xsl:template match="*">
	<Application Language="en-us" Authorization="YES">
		<xsl:attribute name="Name">
			<xsl:value-of select="name()" /><!-- name of root element. (config->ID) -->
		</xsl:attribute>
		<xsl:attribute name="Label">
			<xsl:value-of select="//repository/config/@label" /><!-- config->Label -->
		</xsl:attribute>
		<xsl:attribute name="Charset">
			<xsl:value-of select="//repository/config/@charset" /><!-- config->Charset -->
		</xsl:attribute>

		<Config>
			<CommonGatewayInterface Engine="ApacheRequest">
				<Params
					Pragma        = "no-cache"
					Cache_Control = "no-cache, must-revalidate, no-store"
				/>
			</CommonGatewayInterface>

			<Host Debug="YES">
				<xsl:attribute name="Name">
					<xsl:value-of select="concat(name(), '.deploy')" />
				</xsl:attribute>
				<xsl:attribute name="ServerName">
					<xsl:value-of select="//repository/config/@ServerName" />
				</xsl:attribute>
				<xsl:attribute name="ServerPort">
					<xsl:value-of select="//repository/config/@ServerPort" />
				</xsl:attribute>
				<xsl:attribute name="PerlLibPath">
					<xsl:value-of select="//repository/config/@PerlLibPath" />
				</xsl:attribute>
				<xsl:attribute name="ProjectPath">
					<xsl:value-of select="//repository/config/@ProjectPath" />
				</xsl:attribute>
			</Host>
			<xsl:comment>you can add anofer host for test, production, etc.</xsl:comment>
		</Config>

		<DataSource>
			<xsl:apply-templates select="//repository/schema_list" mode="DataSource" />
		</DataSource>

		<Entitys>
			<xsl:apply-templates select="//repository/schema_list/tables" mode="entity" />
		</Entitys>


		<Relations>
			<xsl:apply-templates select="//repository/schema_list/tables[boolean(has_one)]" mode="relation" />
		</Relations>

		<MenuGroups>
			<Group Name="" Title="">
				<xsl:attribute name="Name">
					<xsl:value-of select="name()" /><!-- name of root element. (config->ID) -->
				</xsl:attribute>
				<xsl:attribute name="Title">
					<xsl:value-of select="//repository/config/@label" /><!-- config->Label -->
				</xsl:attribute>
				<xsl:apply-templates select="//repository/schema_list/tables" mode="menugroups" />
			</Group>
		</MenuGroups>
	</Application>
</xsl:template>

<!-- Create DataSource's list -->
<xsl:template match="//repository/schema_list" mode="DataSource">
	<Type>
		<xsl:attribute name="Name">
			<xsl:value-of select="@type" />
		</xsl:attribute>
		<Source>
			<xsl:attribute name="Name">
				<xsl:value-of select="config/@db_source" />
			</xsl:attribute>
			<xsl:attribute name="Engine">
				<xsl:value-of select="config/@db_engine" />
			</xsl:attribute>
			<xsl:if test="boolean(@catalog)">
			<xsl:attribute name="Catalog">
				<xsl:value-of select="@catalog" />
			</xsl:attribute>
			</xsl:if>
			<xsl:attribute name="Schema">
				<xsl:value-of select="@schema" />
			</xsl:attribute>
			<xsl:attribute name="User">
				<xsl:value-of select="config/@db_user" />
			</xsl:attribute>
			<xsl:attribute name="Password">
				<xsl:value-of select="config/@db_password" />
			</xsl:attribute>
			<xsl:attribute name="Charset">
				<xsl:value-of select="config/@db_charset" />
			</xsl:attribute>
			<xsl:attribute name="Params">
				<xsl:value-of select="config/@db_params" />
			</xsl:attribute>
		</Source>
	</Type>
</xsl:template>

<!-- Create a list of Entities -->
<xsl:template match="//repository/schema_list/tables" mode="entity">
<xsl:variable name="sourceRef" select="concat(../@type, '.', ../config/@db_source)"/>
	<Entity Id="" Name="" Type="Table" Label="" Extends=""> <!-- ABSTRACT | BIND | TABLE | VIEW -->
		<xsl:attribute name="Id">
			<xsl:value-of select="@tId" />
		</xsl:attribute>
		<xsl:attribute name="Type">
			<xsl:value-of select="@type" />
		</xsl:attribute>
		<xsl:attribute name="Name"> <!-- entity name (We assume that the name of the entity corresponds to the name table. And the table name starts with 'tbl' or 't_' for tables and start with 'v_' for the view.) -->
			<xsl:call-template name="convertTable2Entity">
				<xsl:with-param name="name" select="@name"/>
			</xsl:call-template>
		</xsl:attribute>
		<xsl:attribute name="DataSourceTypeRef">
			<xsl:value-of select="../@type" /><!-- the reference to DBI or Resource -->
		</xsl:attribute>
		<xsl:attribute name="DataSourceNameRef">
			<xsl:value-of select="../config/@db_source" /><!-- the reference to the name of the data source -->



( run in 0.867 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )