changeset 8:5fe2e5724331

sync
author cin
date Wed, 07 Mar 2018 15:54:22 +0300
parents 3fe157be5141
children d3542662cf70
files xslt/model.xsl
diffstat 1 files changed, 35 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/xslt/model.xsl	Tue Mar 06 19:27:25 2018 +0300
+++ b/xslt/model.xsl	Wed Mar 07 15:54:22 2018 +0300
@@ -168,46 +168,60 @@
 	</xsl:template>
 	
 	<!-- expand-member templates are used to process relations
-	and keys and provide usefull information like properties of
-	the entity which are members of this relation or key.
+	and keys and provide usefull information. This mode is designed
+	to recursively traverse members expanding details like special
+	properties generated by relations.
+	
+	expand-member-reference is special mode used to traverse inside
+	members which are referenced from relations. By default this mode
+	does nothing.
+	
+	Use this templates to produce intermediate model for further
+	processing by specific code-generators.
 	
 	@special - means that the member is a composite part and isn't
 	accessible directly
 	-->
 	
+	<xsl:template match="*" mode="expand-member">
+		<xsl:apply-templates mode="expand-member"/>
+	</xsl:template>
+	<xsl:template match="text()" mode="expand-member"/>
+	
+	<xsl:template match="*|text()" mode="expand-member-reference"/>
+	
 	<!-- short form of primaryKey{@name, @type} -->
 	<xsl:template match="m:primaryKey" mode="expand-member">
-		<xsl:copy>
-			<xsl:copy-of select="@*"/>
+		<xsl:variable name="specialProperty">
 			<m:property special="true">
 				<xsl:copy-of select="@*" />
+				<m:hiddenBy name="{@name}" type="{@declaringType}"/>
 				<xsl:copy-of select="*" />
 			</m:property>
-		</xsl:copy>
+		</xsl:variable>
+		<xsl:apply-templates select="exsl:node-set($specialProperty)" mode="expand-member"/>
+		<xsl:apply-templates mode="expand-member"/>
 	</xsl:template>
 	
 	<!-- long form of primaryKey{ member{@name}+, property{@name, @type} }  -->
 	<xsl:template match="m:primaryKey[m:member | m:property]" mode="expand-member">
-		<xsl:copy>
-			<xsl:copy-of select="@*"/>
-			<xsl:apply-templates mode="expand-member"/>
-		</xsl:copy>
-	</xsl:template>
-	
-	<!-- stand alone properties -->
-	<xsl:template match="m:property" mode="expand-member">
-		<xsl:copy-of select="."/>
+		<xsl:apply-templates mode="expand-member"/>
 	</xsl:template>
 	
 	<!-- properties declared inside relations, they are @special -->
 	<xsl:template match="m:primaryKey/m:property | m:thisKey/m:property" mode="expand-member">
-		<xsl:copy>
-			<xsl:attribute name="special">true</xsl:attribute>
-			<xsl:copy-of select="@*"/>
-			<xsl:copy-of select="*"/>
-		</xsl:copy>
+		<xsl:variable name="specialProperty">
+			<xsl:copy>
+				<xsl:attribute name="special">true</xsl:attribute>
+				<xsl:copy-of select="@*"/>
+				<m:hiddenBy name="{@name}" type="{@declaringType}"/>
+				<xsl:copy-of select="*"/>
+			</xsl:copy>
+		</xsl:variable>
+		<xsl:apply-templates select="exsl:node-set($specialProperty)" mode="expand-member"/>
 	</xsl:template>
 	
+	<!-- traverse inside referenced members -->
 	<xsl:template match="m:member" mode="expand-member">
 		<xsl:param name="declaringType"/>
 		<xsl:variable name="expanded">
@@ -217,18 +231,10 @@
 			</xsl:call-template>
 		</xsl:variable>
 		<!-- recusive expand -->
-		<xsl:apply-templates select="exsl:node-set($expanded)" mode="expand-member"/>
+		<xsl:apply-templates select="exsl:node-set($expanded)" mode="expand-member-reference"/>
 	</xsl:template>
 	
-	<xsl:template match="m:hasA" mode="expand-member">
-		<xsl:copy>
-			<xsl:copy-of select="@*"/>
-			
-			<xsl:apply-templates mode="expand-member"/>
-		</xsl:copy>
-	</xsl:template>
-	
-	<xsl:template match="m:thisKey" mode="expand-member">
+	<xsl:template match="m:hasA/m:thisKey" mode="expand-member">
 		<xsl:variable name="otherKey">
 			<xsl:call-template name="getPrimaryKey">
 				<xsl:with-param name="type" select="../@type"/>