comparison xslt/csharp.xsl @ 0:cbdada054b4a

Basic schemas for generating csharp internal dom from model definition
author cin
date Wed, 21 Feb 2018 03:01:53 +0300
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:cbdada054b4a
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet version="1.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:cs="http://implab.org/schemas/code-dom/csharp.v1.xsd">
5 <xsl:import href="text-tools.xsl" />
6
7 <!-- CODE GENERATION -->
8
9 <!-- GENERATE NAMESPACE -->
10 <xsl:template match="cs:namespace">
11 <xsl:param name="level" select="0" />
12 <xsl:call-template name="write-line">
13 <xsl:with-param name="level" select="$level" />
14 <xsl:with-param name="text">
15 <xsl:text>namespace </xsl:text>
16 <xsl:value-of select="@name" />
17 <xsl:text> {</xsl:text>
18 </xsl:with-param>
19 </xsl:call-template>
20 <xsl:apply-templates>
21 <xsl:with-param name="level" select="$level+1" />
22 </xsl:apply-templates>
23 <xsl:call-template name="write-line">
24 <xsl:with-param name="level" select="$level" />
25 <xsl:with-param name="text">
26 }
27 </xsl:with-param>
28 </xsl:call-template>
29 </xsl:template>
30
31 <!-- GENERATE CLASS -->
32 <xsl:template match="cs:class">
33 <xsl:param name="level" select="0" />
34 <xsl:call-template name="write-line">
35 <xsl:with-param name="level" select="$level" />
36 <xsl:with-param name="text">
37 <xsl:text>class </xsl:text>
38 <xsl:value-of select="@name" />
39 <xsl:text> {</xsl:text>
40 </xsl:with-param>
41 </xsl:call-template>
42
43 <xsl:apply-templates mode="members">
44 <xsl:with-param name="level" select="$level+1" />
45 <xsl:with-param name="declaringType" select="." />
46 </xsl:apply-templates>
47
48 <xsl:call-template name="write-line">
49 <xsl:with-param name="level" select="$level" />
50 <xsl:with-param name="text" select="'}'" />
51 </xsl:call-template>
52 </xsl:template>
53
54 <!-- GENERATE FIELDS -->
55 <xsl:template match="cs:field" mode="members">
56 <xsl:param name="level" select="0" />
57 <xsl:call-template name="write-line">
58 <xsl:with-param name="level" select="$level" />
59 <xsl:with-param name="text">
60 <xsl:value-of select="concat(@type,' ', @name)" />
61 <xsl:if test="@initializer">
62 <xsl:text> = </xsl:text>
63 <xsl:value-of select="@initializer" />
64 </xsl:if>
65 <xsl:text>;</xsl:text>
66 </xsl:with-param>
67 </xsl:call-template>
68 </xsl:template>
69
70 <!-- GENERATE PROPERTIES -->
71 <xsl:template match="cs:property" mode="members">
72 <xsl:param name="level" select="0" />
73 <xsl:call-template name="write-line">
74 <xsl:with-param name="level" select="$level" />
75 <xsl:with-param name="text" select="concat(@type,' ', @name, ' {')" />
76 </xsl:call-template>
77 <xsl:apply-templates>
78 <xsl:with-param name="level" select="$level + 1" />
79 </xsl:apply-templates>
80 <xsl:call-template name="write-line">
81 <xsl:with-param name="level" select="$level" />
82 <xsl:with-param name="text" select="'}'" />
83 </xsl:call-template>
84 </xsl:template>
85 </xsl:stylesheet>