[r84]: / trunk / cforge / cforge / Package / CFORGE / Scripts / plcopenxml.xslt  Maximize  Restore  History

Download this file

197 lines (182 with data), 5.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:po="http://www.plcopen.org/xml/tc6_0200">

<!--
 | Parse POU start tags
-->
<xsl:template match="po:pou[@pouType='functionBlock']">
      <xsl:text>---
</xsl:text>
<!--      <xsl:value-of select="po:interface/po:documentation"/>-->
	  <xsl:call-template name="trim">
       		     <xsl:with-param name="input" select="po:interface/po:documentation"/>
          </xsl:call-template>
      <xsl:text>
~~~ST
</xsl:text>
      <xsl:text>FUNCTION_BLOCK </xsl:text><xsl:value-of select="@name" />
      <xsl:apply-templates select="po:interface"/>
      <xsl:text>
~~~
</xsl:text>
      <xsl:apply-templates select="po:body"/>
      <xsl:apply-templates select="po:addData/po:data/po:Method"/>
</xsl:template>
<xsl:template match="po:pou[@pouType='program']">
      <xsl:text>---
~~~ST
</xsl:text>
      <xsl:text>PROGRAM </xsl:text><xsl:value-of select="@name" />
      <xsl:apply-templates select="po:interface"/>
      <xsl:text>
~~~
</xsl:text>
      <xsl:apply-templates select="po:body"/>
</xsl:template>
<xsl:template match="po:Method">
      <xsl:text>---
~~~ST
</xsl:text>
      <xsl:text>METHOD </xsl:text><xsl:value-of select="@name" />
      <xsl:text>: </xsl:text>
      <xsl:apply-templates select="*/po:returnType"/>
      <xsl:apply-templates select="po:interface"/>
      <xsl:text>
~~~
</xsl:text>
      <xsl:apply-templates select="po:body"/>
</xsl:template>

<!--
 | Parse POU body
-->
<xsl:template match="po:body">
      <xsl:apply-templates select="*|@*"/>
</xsl:template>


<!--
 | Parse Interface (also finish the start tag, to be able to set "EXTENDS" or "IMPLEMENTS".
-->
<xsl:template match="po:interface">
      <xsl:if test="po:addData/po:data/po:Inheritance/po:Extends">
      	      <xsl:text> EXTENDS </xsl:text>
	      <xsl:value-of select="po:addData/po:data/po:Inheritance/po:Extends"/>
      </xsl:if>
      <xsl:text>
</xsl:text>
      <xsl:apply-templates select="po:localVars|po:tempVars|po:inputVars|po:outputVars|po:inOutVars|po:externalVars|po:globalVars"/>
</xsl:template>

<!--
 | Variables (Part of the interface)
-->
<xsl:template match="po:localVars">
      <xsl:text>VAR
</xsl:text>
      <xsl:apply-templates select="po:variable"/>
      <xsl:text>END_VAR
</xsl:text>
</xsl:template>
<xsl:template match="po:tempVars">
      <xsl:text>VAR_TEMP
</xsl:text>
      <xsl:apply-templates select="po:variable"/>
      <xsl:text>END_VAR
</xsl:text>
</xsl:template>
<xsl:template match="po:inputVars">
      <xsl:text>VAR_INPUT
</xsl:text>
      <xsl:apply-templates select="po:variable"/>
      <xsl:text>END_VAR
</xsl:text>
</xsl:template>
<xsl:template match="po:outputVars">
      <xsl:text>VAR_OUTPUT
</xsl:text>
      <xsl:apply-templates select="po:variable"/>
      <xsl:text>END_VAR
</xsl:text>
</xsl:template>
<xsl:template match="po:inOutVars">
      <xsl:text>VAR_INOUT
</xsl:text>
      <xsl:apply-templates select="po:variable"/>
      <xsl:text>END_VAR
</xsl:text>
</xsl:template>
<xsl:template match="po:externalVars">
      <xsl:text>VAR_EXTERNAL
</xsl:text>
      <xsl:apply-templates select="po:variable"/>
      <xsl:text>END_VAR
</xsl:text>
</xsl:template>
<xsl:template match="po:globalVars">
      <xsl:text>VAR_GLOBAL
</xsl:text>
      <xsl:apply-templates select="po:variable"/>
      <xsl:text>END_VAR
</xsl:text>
</xsl:template>

<xsl:template match="po:variable">
<xsl:text>    </xsl:text>
<xsl:if test="@name">
      <xsl:value-of select="@name"/>
      <xsl:text>: </xsl:text>
      <xsl:apply-templates select="po:type"/>
      <xsl:text>;
</xsl:text>
</xsl:if>
</xsl:template>

<xsl:template match="po:type|po:baseType|po:returnType">
      <xsl:if test="po:derived">
	      <xsl:value-of select="po:derived/@name"/>
      </xsl:if>
      <xsl:if test="po:array">
      	      <xsl:text>ARRAY [</xsl:text>
	      <xsl:value-of select="po:array/dimension/@lower"/>
      	      <xsl:text>..</xsl:text>
	      <xsl:value-of select="po:array/dimension/@upper"/>
      	      <xsl:text>] OF </xsl:text>
	      <xsl:apply-templates select="po:baseType"/>
      </xsl:if>
      <xsl:if test="not(po:derived) and not(po:array) and not(po:struct)">
	      <xsl:value-of select="name(*[1])"/>
      </xsl:if>
</xsl:template>


<!--
 | Implement the presentation of the different languages
-->
<xsl:template match="po:ST">
      <xsl:text>~~~ST
</xsl:text>
      <xsl:value-of select="*[1]"/>
      <xsl:text>
~~~
</xsl:text>
</xsl:template>

<xsl:template name="trim">
        <xsl:param name="input"/>
        <xsl:choose>
                <xsl:when test="starts-with($input,' ')">
                        <xsl:call-template name="trim">
                                <xsl:with-param name="input" select="substring-after($input,' ')"/>
                        </xsl:call-template>
                </xsl:when>
                <xsl:when test="substring($input, string-length($input) ) = ' ' ">
                        <xsl:call-template name="trim">
                                <xsl:with-param name="input" select="substring($input, 1,
string-length($input)-1)"/>
                        </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                        <xsl:value-of select="$input"/>
                </xsl:otherwise>
        </xsl:choose>
</xsl:template>
<!--
 | Fetch and ignore rest
-->
<xsl:template match="*|@*">
      <xsl:apply-templates select="*|@*"/>
</xsl:template>

</xsl:stylesheet>