Ambrosia

 view release on metacpan or  search on metacpan

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

				</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 -->
		</xsl:attribute>
		<xsl:attribute name="SourcePath"> <!-- the table name | the file name -->
			<xsl:value-of select="@name" />
		</xsl:attribute>

		<xsl:if test="boolean(@KEY)">
		<Key>
			<xsl:if test="boolean(@AUTO_UNIQUE_VALUE)">
				<xsl:attribute name="AutoUniqueValue">
					<xsl:text>YES</xsl:text>
				</xsl:attribute>
			</xsl:if>
			<xsl:apply-templates select="column" mode="key"/>
		</Key>
		</xsl:if>

		<xsl:apply-templates select="column" mode="fields"/>

	</Entity>
</xsl:template>

<!-- Create a list of Relations -->
<xsl:template match="//repository/schema_list/tables[boolean(has_one)]" mode="relation">
	<Relation RefId="" Type="">
		<xsl:attribute name="RefId">
			<xsl:value-of select="@tId" /><!-- the reference to Entity -->
		</xsl:attribute>
		<xsl:attribute name="Type"> <!-- the reference to entity -->
			<xsl:call-template name="convertTable2Entity">



( run in 1.305 second using v1.01-cache-2.11-cpan-40ba7b3775d )