plcopen/variables_infos.xslt
changeset 1308 ad61268dbdb6
child 1317 177d7cd76a3e
equal deleted inserted replaced
1307:26e8b99bc2c3 1308:ad61268dbdb6
       
     1 <xsl:stylesheet version="1.0"
       
     2     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       
     3     xmlns:ppx="http://www.plcopen.org/xml/tc6_0201"
       
     4     xmlns:xhtml="http://www.w3.org/1999/xhtml"
       
     5     xmlns:ns="var_infos_ns"
       
     6     extension-element-prefixes="ns"
       
     7     exclude-result-prefixes="ns">
       
     8   <xsl:template match="ppx:returnType">
       
     9     <ReturnType>
       
    10       <Type><xsl:apply-templates/></Type>
       
    11       <Tree><xsl:apply-templates mode="var_tree"/></Tree>
       
    12     </ReturnType>
       
    13   </xsl:template>
       
    14   <xsl:template match="ppx:localVars">
       
    15     <xsl:call-template name="variables_infos">
       
    16       <xsl:with-param name="var_class" select="'Local'"/>
       
    17     </xsl:call-template>
       
    18   </xsl:template>
       
    19   <xsl:template match="ppx:globalVars">
       
    20     <xsl:call-template name="variables_infos">
       
    21       <xsl:with-param name="var_class" select="'Global'"/>
       
    22     </xsl:call-template>
       
    23   </xsl:template>
       
    24   <xsl:template match="ppx:externalVars">
       
    25     <xsl:call-template name="variables_infos">
       
    26       <xsl:with-param name="var_class" select="'External'"/>
       
    27     </xsl:call-template>
       
    28   </xsl:template>
       
    29   <xsl:template match="ppx:tempVars">
       
    30     <xsl:call-template name="variables_infos">
       
    31       <xsl:with-param name="var_class" select="'Temp'"/>
       
    32     </xsl:call-template>
       
    33   </xsl:template>
       
    34   <xsl:template match="ppx:inputVars">
       
    35     <xsl:call-template name="variables_infos">
       
    36       <xsl:with-param name="var_class" select="'Input'"/>
       
    37     </xsl:call-template>
       
    38   </xsl:template>
       
    39   <xsl:template match="ppx:outputVars">
       
    40     <xsl:call-template name="variables_infos">
       
    41       <xsl:with-param name="var_class" select="'Output'"/>
       
    42     </xsl:call-template>
       
    43   </xsl:template>
       
    44   <xsl:template match="inOutVars">
       
    45     <xsl:call-template name="variables_infos">
       
    46       <xsl:with-param name="var_class" select="'InOut'"/>
       
    47     </xsl:call-template>
       
    48   </xsl:template>
       
    49   <xsl:template name="variables_infos">
       
    50     <xsl:param name="var_class"/>
       
    51     <xsl:variable name="var_option">
       
    52       <xsl:choose>
       
    53         <xsl:when test="@constant='true' or @constant='1'">
       
    54           <xsl:text>Constant</xsl:text>
       
    55         </xsl:when>
       
    56         <xsl:when test="@retain='true' or @retain='1'">
       
    57           <xsl:text>Retain</xsl:text>
       
    58         </xsl:when>
       
    59         <xsl:when test="@nonretain='true' or @nonretain='1'">
       
    60           <xsl:text>Non-Retain</xsl:text>
       
    61         </xsl:when>
       
    62       </xsl:choose>
       
    63     </xsl:variable>
       
    64     <xsl:for-each select="ppx:variable">
       
    65       <ns:add_variable>
       
    66         <Name><xsl:value-of select="@name"/></Name>
       
    67         <Class><xsl:value-of select="$var_class"/></Class>
       
    68         <Type><xsl:apply-templates select="ppx:type"/></Type>
       
    69         <Option><xsl:value-of select="$var_option"/></Option>
       
    70         <Location><xsl:value-of select="@address"/></Location>
       
    71         <Initial_Value><xsl:apply-templates select="ppx:initialValue"/></Initial_Value>
       
    72         <Edit/>
       
    73         <Tree><xsl:apply-templates select="ppx:type" mode="var_tree"/></Tree>
       
    74         <Documentation>
       
    75           <xsl:value-of select="ppx:documentation/xhtml:p/text()"/>
       
    76         </Documentation>
       
    77       </ns:add_variable>
       
    78     </xsl:for-each>
       
    79   </xsl:template>
       
    80   <xsl:template match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/ppx:derived">
       
    81     <xsl:value-of select="@name"/>
       
    82   </xsl:template>
       
    83   <xsl:template match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/ppx:array">
       
    84     <array>
       
    85       <xsl:apply-templates select="ppx:baseType"/>
       
    86       <xsl:for-each select="ppx:dimension">
       
    87         <dimension>
       
    88           <xsl:attribute name="lower">
       
    89             <xsl:value-of select="@lower"/>
       
    90           </xsl:attribute>
       
    91           <xsl:attribute name="upper">
       
    92             <xsl:value-of select="@upper"/>
       
    93           </xsl:attribute>
       
    94         </dimension>
       
    95       </xsl:for-each>
       
    96     </array>
       
    97   </xsl:template>
       
    98   <xsl:template match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/ppx:string">
       
    99     <xsl:text>STRING</xsl:text>
       
   100   </xsl:template>
       
   101   <xsl:template match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/ppx:wstring">
       
   102     <xsl:text>WSTRING</xsl:text>
       
   103   </xsl:template>
       
   104   <xsl:template match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/*">
       
   105     <xsl:value-of select="local-name()"/>
       
   106   </xsl:template>
       
   107     <xsl:template match="ppx:initialValue">
       
   108     <xsl:apply-templates/>
       
   109   </xsl:template>
       
   110   <xsl:template match="ppx:value">
       
   111     <xsl:choose>
       
   112       <xsl:when test="@repetitionValue">
       
   113         <xsl:value-of select="@repetitionValue"/>
       
   114         <xsl:text>(</xsl:text>
       
   115         <xsl:apply-templates/>
       
   116         <xsl:text>)</xsl:text>
       
   117       </xsl:when>
       
   118       <xsl:when test="@member">
       
   119         <xsl:value-of select="@member"/>
       
   120         <xsl:text> := </xsl:text>
       
   121         <xsl:apply-templates/>
       
   122       </xsl:when>
       
   123       <xsl:otherwise>
       
   124         <xsl:apply-templates/>
       
   125       </xsl:otherwise>
       
   126     </xsl:choose>
       
   127   </xsl:template>
       
   128   <xsl:template match="ppx:simpleValue">
       
   129     <xsl:value-of select="@value"/>
       
   130   </xsl:template>
       
   131   <xsl:template match="ppx:arrayValue">
       
   132     <xsl:text>[</xsl:text>
       
   133     <xsl:for-each select="ppx:value">
       
   134       <xsl:apply-templates select="."/>
       
   135       <xsl:choose>
       
   136         <xsl:when test="position()!=last()">
       
   137           <xsl:text>, </xsl:text>
       
   138         </xsl:when>
       
   139       </xsl:choose>
       
   140     </xsl:for-each>
       
   141     <xsl:text>]</xsl:text>
       
   142   </xsl:template>
       
   143   <xsl:template match="ppx:structValue">
       
   144     <xsl:text>(</xsl:text>
       
   145     <xsl:for-each select="ppx:value">
       
   146       <xsl:apply-templates select="."/>
       
   147       <xsl:choose>
       
   148         <xsl:when test="position()!=last()">
       
   149           <xsl:text>, </xsl:text>
       
   150         </xsl:when>
       
   151       </xsl:choose>
       
   152     </xsl:for-each>
       
   153     <xsl:text>)</xsl:text>
       
   154   </xsl:template>
       
   155   <xsl:template match="ppx:pou" mode="var_tree">
       
   156     <xsl:apply-templates select="ppx:interface/*[self::ppx:inputVars or self::ppx:inOutVars or self::ppx:outputVars]/ppx:variable" mode="var_tree"/>
       
   157   </xsl:template>
       
   158   <xsl:template match="ppx:variable" mode="var_tree">
       
   159     <var>
       
   160       <xsl:attribute name="name">
       
   161         <xsl:value-of select="@name"/>
       
   162       </xsl:attribute>
       
   163       <xsl:apply-templates select="ppx:type" mode="var_tree"/>
       
   164     </var>
       
   165   </xsl:template>
       
   166   <xsl:template match="ppx:dataType">
       
   167     <xsl:apply-templates select="ppx:baseType" mode="var_tree"/>
       
   168   </xsl:template>
       
   169   <xsl:template match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/ppx:struct" mode="var_tree">
       
   170     <xsl:apply-templates select="ppx:variable" mode="var_tree"/>
       
   171   </xsl:template>
       
   172   <xsl:template match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/ppx:derived" mode="var_tree">
       
   173     <ns:var_tree/>
       
   174     <xsl:choose>
       
   175       <xsl:when test="count(./*) > 0">
       
   176         <xsl:apply-templates mode="var_tree"/>
       
   177       </xsl:when>
       
   178       <xsl:otherwise>
       
   179         <xsl:value-of select="@name"/>
       
   180       </xsl:otherwise>
       
   181     </xsl:choose>
       
   182   </xsl:template>
       
   183   <xsl:template match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/ppx:array" mode="var_tree">
       
   184     <xsl:apply-templates select="ppx:baseType" mode="var_tree"/>
       
   185     <xsl:for-each select="ppx:dimension">
       
   186       <dimension>
       
   187         <xsl:attribute name="lower">
       
   188           <xsl:value-of select="@lower"/>
       
   189         </xsl:attribute>
       
   190         <xsl:attribute name="upper">
       
   191           <xsl:value-of select="@upper"/>
       
   192         </xsl:attribute>
       
   193       </dimension>
       
   194     </xsl:for-each>
       
   195   </xsl:template>
       
   196   <xsl:template match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/ppx:string" mode="var_tree">
       
   197     <xsl:text>STRING</xsl:text>
       
   198   </xsl:template>
       
   199   <xsl:template match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/ppx:wstring" mode="var_tree">
       
   200     <xsl:text>WSTRING</xsl:text>
       
   201   </xsl:template>
       
   202   <xsl:template match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/*" mode="var_tree">
       
   203     <xsl:value-of select="local-name()"/>
       
   204   </xsl:template>
       
   205   <xsl:template match="text()"/>
       
   206   <xsl:template match="text()" mode="var_tree"/>
       
   207 </xsl:stylesheet>