Diff of /trunk/cforge/cforge/Package/CFORGE/Scripts/plcopenxml.xslt [000000] .. [r26]  Maximize  Restore

Switch to unified view

a b/trunk/cforge/cforge/Package/CFORGE/Scripts/plcopenxml.xslt
1
<?xml version="1.0"?>
2
<xsl:stylesheet version="1.0"
3
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4
    xmlns:po="http://www.plcopen.org/xml/tc6_0200">
5
6
<!--
7
 | Parse POU start tags
8
-->
9
<xsl:template match="po:pou[@pouType='functionBlock']">
10
      <xsl:text>---
11
</xsl:text>
12
<!--      <xsl:value-of select="po:interface/po:documentation"/>-->
13
      <xsl:call-template name="trim">
14
                 <xsl:with-param name="input" select="po:interface/po:documentation"/>
15
          </xsl:call-template>
16
      <xsl:text>
17
~~~ST
18
</xsl:text>
19
      <xsl:text>FUNCTION_BLOCK </xsl:text><xsl:value-of select="@name" />
20
      <xsl:apply-templates select="po:interface"/>
21
      <xsl:text>
22
~~~
23
</xsl:text>
24
      <xsl:apply-templates select="po:body"/>
25
      <xsl:apply-templates select="po:addData/po:data/po:Method"/>
26
</xsl:template>
27
<xsl:template match="po:pou[@pouType='program']">
28
      <xsl:text>---
29
~~~ST
30
</xsl:text>
31
      <xsl:text>PROGRAM </xsl:text><xsl:value-of select="@name" />
32
      <xsl:apply-templates select="po:interface"/>
33
      <xsl:text>
34
~~~
35
</xsl:text>
36
      <xsl:apply-templates select="po:body"/>
37
</xsl:template>
38
<xsl:template match="po:Method">
39
      <xsl:text>---
40
~~~ST
41
</xsl:text>
42
      <xsl:text>METHOD </xsl:text><xsl:value-of select="@name" />
43
      <xsl:text>: </xsl:text>
44
      <xsl:apply-templates select="*/po:returnType"/>
45
      <xsl:apply-templates select="po:interface"/>
46
      <xsl:text>
47
~~~
48
</xsl:text>
49
      <xsl:apply-templates select="po:body"/>
50
</xsl:template>
51
52
<!--
53
 | Parse POU body
54
-->
55
<xsl:template match="po:body">
56
      <xsl:apply-templates select="*|@*"/>
57
</xsl:template>
58
59
60
<!--
61
 | Parse Interface (also finish the start tag, to be able to set "EXTENDS" or "IMPLEMENTS".
62
-->
63
<xsl:template match="po:interface">
64
      <xsl:if test="po:addData/po:data/po:Inheritance/po:Extends">
65
              <xsl:text> EXTENDS </xsl:text>
66
          <xsl:value-of select="po:addData/po:data/po:Inheritance/po:Extends"/>
67
      </xsl:if>
68
      <xsl:text>
69
</xsl:text>
70
      <xsl:apply-templates select="po:localVars|po:tempVars|po:inputVars|po:outputVars|po:inOutVars|po:externalVars|po:globalVars"/>
71
</xsl:template>
72
73
<!--
74
 | Variables (Part of the interface)
75
-->
76
<xsl:template match="po:localVars">
77
      <xsl:text>VAR
78
</xsl:text>
79
      <xsl:apply-templates select="po:variable"/>
80
      <xsl:text>END_VAR
81
</xsl:text>
82
</xsl:template>
83
<xsl:template match="po:tempVars">
84
      <xsl:text>VAR_TEMP
85
</xsl:text>
86
      <xsl:apply-templates select="po:variable"/>
87
      <xsl:text>END_VAR
88
</xsl:text>
89
</xsl:template>
90
<xsl:template match="po:inputVars">
91
      <xsl:text>VAR_INPUT
92
</xsl:text>
93
      <xsl:apply-templates select="po:variable"/>
94
      <xsl:text>END_VAR
95
</xsl:text>
96
</xsl:template>
97
<xsl:template match="po:outputVars">
98
      <xsl:text>VAR_OUTPUT
99
</xsl:text>
100
      <xsl:apply-templates select="po:variable"/>
101
      <xsl:text>END_VAR
102
</xsl:text>
103
</xsl:template>
104
<xsl:template match="po:inOutVars">
105
      <xsl:text>VAR_INOUT
106
</xsl:text>
107
      <xsl:apply-templates select="po:variable"/>
108
      <xsl:text>END_VAR
109
</xsl:text>
110
</xsl:template>
111
<xsl:template match="po:externalVars">
112
      <xsl:text>VAR_EXTERNAL
113
</xsl:text>
114
      <xsl:apply-templates select="po:variable"/>
115
      <xsl:text>END_VAR
116
</xsl:text>
117
</xsl:template>
118
<xsl:template match="po:globalVars">
119
      <xsl:text>VAR_GLOBAL
120
</xsl:text>
121
      <xsl:apply-templates select="po:variable"/>
122
      <xsl:text>END_VAR
123
</xsl:text>
124
</xsl:template>
125
126
<xsl:template match="po:variable">
127
<xsl:text>    </xsl:text>
128
<xsl:if test="@name">
129
      <xsl:value-of select="@name"/>
130
      <xsl:text>: </xsl:text>
131
      <xsl:apply-templates select="po:type"/>
132
      <xsl:text>;
133
</xsl:text>
134
</xsl:if>
135
</xsl:template>
136
137
<xsl:template match="po:type|po:baseType|po:returnType">
138
      <xsl:if test="po:derived">
139
          <xsl:value-of select="po:derived/@name"/>
140
      </xsl:if>
141
      <xsl:if test="po:array">
142
              <xsl:text>ARRAY [</xsl:text>
143
          <xsl:value-of select="po:array/dimension/@lower"/>
144
              <xsl:text>..</xsl:text>
145
          <xsl:value-of select="po:array/dimension/@upper"/>
146
              <xsl:text>] OF </xsl:text>
147
          <xsl:apply-templates select="po:baseType"/>
148
      </xsl:if>
149
      <xsl:if test="not(po:derived) and not(po:array) and not(po:struct)">
150
          <xsl:value-of select="name(*[1])"/>
151
      </xsl:if>
152
</xsl:template>
153
154
155
<!--
156
 | Implement the presentation of the different languages
157
-->
158
<xsl:template match="po:ST">
159
      <xsl:text>~~~ST
160
</xsl:text>
161
      <xsl:value-of select="*[1]"/>
162
      <xsl:text>
163
~~~
164
</xsl:text>
165
</xsl:template>
166
167
<xsl:template name="trim">
168
        <xsl:param name="input"/>
169
        <xsl:choose>
170
                <xsl:when test="starts-with($input,' ')">
171
                        <xsl:call-template name="trim">
172
                                <xsl:with-param name="input" select="substring-after($input,' ')"/>
173
                        </xsl:call-template>
174
                </xsl:when>
175
                <xsl:when test="substring($input, string-length($input) ) = ' ' ">
176
                        <xsl:call-template name="trim">
177
                                <xsl:with-param name="input" select="substring($input, 1,
178
string-length($input)-1)"/>
179
                        </xsl:call-template>
180
                </xsl:when>
181
                <xsl:otherwise>
182
                        <xsl:value-of select="$input"/>
183
                </xsl:otherwise>
184
        </xsl:choose>
185
</xsl:template>
186
<!--
187
 | Fetch and ignore rest
188
-->
189
<xsl:template match="*|@*">
190
      <xsl:apply-templates select="*|@*"/>
191
</xsl:template>
192
193
</xsl:stylesheet>
194
    
195
196