svghmi/analyse_widget.xslt
branchsvghmi
changeset 3235 b2b6bf45aa2d
child 3241 fe945f1f48b7
equal deleted inserted replaced
3234:f2bfb047d0e6 3235:b2b6bf45aa2d
       
     1 <?xml version="1.0"?>
       
     2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:str="http://exslt.org/strings" xmlns:func="http://exslt.org/functions" xmlns:svg="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn svg inkscape">
       
     3   <xsl:output method="xml"/>
       
     4   <xsl:variable name="indexed_hmitree" select="/.."/>
       
     5   <xsl:variable name="pathregex" select="'^([^\[,]+)(\[[^\]]+\])?([\d,]*)$'"/>
       
     6   <xsl:template mode="parselabel" match="*">
       
     7     <xsl:variable name="label" select="@inkscape:label"/>
       
     8     <xsl:variable name="id" select="@id"/>
       
     9     <xsl:variable name="description" select="substring-after($label,'HMI:')"/>
       
    10     <xsl:variable name="_args" select="substring-before($description,'@')"/>
       
    11     <xsl:variable name="args">
       
    12       <xsl:choose>
       
    13         <xsl:when test="$_args">
       
    14           <xsl:value-of select="$_args"/>
       
    15         </xsl:when>
       
    16         <xsl:otherwise>
       
    17           <xsl:value-of select="$description"/>
       
    18         </xsl:otherwise>
       
    19       </xsl:choose>
       
    20     </xsl:variable>
       
    21     <xsl:variable name="_type" select="substring-before($args,':')"/>
       
    22     <xsl:variable name="type">
       
    23       <xsl:choose>
       
    24         <xsl:when test="$_type">
       
    25           <xsl:value-of select="$_type"/>
       
    26         </xsl:when>
       
    27         <xsl:otherwise>
       
    28           <xsl:value-of select="$args"/>
       
    29         </xsl:otherwise>
       
    30       </xsl:choose>
       
    31     </xsl:variable>
       
    32     <xsl:if test="$type">
       
    33       <widget>
       
    34         <xsl:attribute name="id">
       
    35           <xsl:value-of select="$id"/>
       
    36         </xsl:attribute>
       
    37         <xsl:attribute name="type">
       
    38           <xsl:value-of select="$type"/>
       
    39         </xsl:attribute>
       
    40         <xsl:for-each select="str:split(substring-after($args, ':'), ':')">
       
    41           <arg>
       
    42             <xsl:attribute name="value">
       
    43               <xsl:value-of select="."/>
       
    44             </xsl:attribute>
       
    45           </arg>
       
    46         </xsl:for-each>
       
    47         <xsl:variable name="paths" select="substring-after($description,'@')"/>
       
    48         <xsl:for-each select="str:split($paths, '@')">
       
    49           <xsl:if test="string-length(.) &gt; 0">
       
    50             <path>
       
    51               <xsl:variable name="path_match" select="regexp:match(.,$pathregex)"/>
       
    52               <xsl:variable name="pathminmax" select="str:split($path_match[4],',')"/>
       
    53               <xsl:variable name="path" select="$path_match[2]"/>
       
    54               <xsl:variable name="path_accepts" select="$path_match[3]"/>
       
    55               <xsl:variable name="pathminmaxcount" select="count($pathminmax)"/>
       
    56               <xsl:attribute name="value">
       
    57                 <xsl:value-of select="$path"/>
       
    58               </xsl:attribute>
       
    59               <xsl:if test="string-length($path_accepts)">
       
    60                 <xsl:attribute name="accepts">
       
    61                   <xsl:value-of select="$path_accepts"/>
       
    62                 </xsl:attribute>
       
    63               </xsl:if>
       
    64               <xsl:choose>
       
    65                 <xsl:when test="$pathminmaxcount = 2">
       
    66                   <xsl:attribute name="min">
       
    67                     <xsl:value-of select="$pathminmax[1]"/>
       
    68                   </xsl:attribute>
       
    69                   <xsl:attribute name="max">
       
    70                     <xsl:value-of select="$pathminmax[2]"/>
       
    71                   </xsl:attribute>
       
    72                 </xsl:when>
       
    73                 <xsl:when test="$pathminmaxcount = 1 or $pathminmaxcount &gt; 2">
       
    74                   <xsl:message terminate="yes">
       
    75                     <xsl:text>Widget id:</xsl:text>
       
    76                     <xsl:value-of select="$id"/>
       
    77                     <xsl:text> label:</xsl:text>
       
    78                     <xsl:value-of select="$label"/>
       
    79                     <xsl:text> has wrong syntax of path section </xsl:text>
       
    80                     <xsl:value-of select="$pathminmax"/>
       
    81                   </xsl:message>
       
    82                 </xsl:when>
       
    83               </xsl:choose>
       
    84               <xsl:if test="$indexed_hmitree">
       
    85                 <xsl:choose>
       
    86                   <xsl:when test="regexp:test($path,'^\.[a-zA-Z0-9_]+$')">
       
    87                     <xsl:attribute name="type">
       
    88                       <xsl:text>PAGE_LOCAL</xsl:text>
       
    89                     </xsl:attribute>
       
    90                   </xsl:when>
       
    91                   <xsl:when test="regexp:test($path,'^[a-zA-Z0-9_]+$')">
       
    92                     <xsl:attribute name="type">
       
    93                       <xsl:text>HMI_LOCAL</xsl:text>
       
    94                     </xsl:attribute>
       
    95                   </xsl:when>
       
    96                   <xsl:otherwise>
       
    97                     <xsl:variable name="item" select="$indexed_hmitree/*[@hmipath = $path]"/>
       
    98                     <xsl:variable name="pathtype" select="local-name($item)"/>
       
    99                     <xsl:if test="$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')">
       
   100                       <xsl:message terminate="yes">
       
   101                         <xsl:text>Widget id:</xsl:text>
       
   102                         <xsl:value-of select="$id"/>
       
   103                         <xsl:text> label:</xsl:text>
       
   104                         <xsl:value-of select="$label"/>
       
   105                         <xsl:text> path section </xsl:text>
       
   106                         <xsl:value-of select="$pathminmax"/>
       
   107                         <xsl:text> use min and max on non mumeric value</xsl:text>
       
   108                       </xsl:message>
       
   109                     </xsl:if>
       
   110                     <xsl:if test="count($item) = 1">
       
   111                       <xsl:attribute name="index">
       
   112                         <xsl:value-of select="$item/@index"/>
       
   113                       </xsl:attribute>
       
   114                       <xsl:attribute name="type">
       
   115                         <xsl:value-of select="$pathtype"/>
       
   116                       </xsl:attribute>
       
   117                     </xsl:if>
       
   118                   </xsl:otherwise>
       
   119                 </xsl:choose>
       
   120               </xsl:if>
       
   121             </path>
       
   122           </xsl:if>
       
   123         </xsl:for-each>
       
   124       </widget>
       
   125     </xsl:if>
       
   126   </xsl:template>
       
   127   <xsl:template mode="genlabel" match="arg">
       
   128     <xsl:text>:</xsl:text>
       
   129     <xsl:value-of select="@value"/>
       
   130   </xsl:template>
       
   131   <xsl:template mode="genlabel" match="path">
       
   132     <xsl:text>@</xsl:text>
       
   133     <xsl:value-of select="@value"/>
       
   134     <xsl:if test="string-length(@min)&gt;0 or string-length(@max)&gt;0">
       
   135       <xsl:text>,</xsl:text>
       
   136       <xsl:value-of select="@min"/>
       
   137       <xsl:text>,</xsl:text>
       
   138       <xsl:value-of select="@max"/>
       
   139     </xsl:if>
       
   140   </xsl:template>
       
   141   <xsl:template mode="genlabel" match="widget">
       
   142     <xsl:text>HMI:</xsl:text>
       
   143     <xsl:value-of select="@type"/>
       
   144     <xsl:apply-templates mode="genlabel" select="arg"/>
       
   145     <xsl:apply-templates mode="genlabel" select="path"/>
       
   146   </xsl:template>
       
   147   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
       
   148   <xsl:template match="/">
       
   149     <widgets>
       
   150       <xsl:apply-templates mode="parselabel" select="$hmi_elements"/>
       
   151     </widgets>
       
   152   </xsl:template>
       
   153 </xsl:stylesheet>