svghmi/gen_dnd_widget_svg.xslt
branchsvghmi
changeset 3229 c5be4fd425e7
parent 3225 cfa5690c8c15
child 3234 f2bfb047d0e6
equal deleted inserted replaced
3228:80f96db773bd 3229:c5be4fd425e7
     1 <?xml version="1.0"?>
     1 <?xml version="1.0"?>
     2 <xsl:stylesheet xmlns:func="http://exslt.org/functions" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg" xmlns:str="http://exslt.org/strings" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exsl="http://exslt.org/common" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" extension-element-prefixes="ns func exsl regexp str dyn" version="1.0" exclude-result-prefixes="ns func exsl regexp str dyn">
     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:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn">
     3   <xsl:output method="xml"/>
     3   <xsl:output method="xml"/>
     4   <xsl:param name="hmi_path"/>
     4   <xsl:param name="hmi_path"/>
     5   <xsl:variable name="svg" select="/svg:svg"/>
     5   <xsl:variable name="svg" select="/svg:svg"/>
     6   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
     6   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
     7   <xsl:variable name="subhmitree" select="ns:GetSubHMITree()"/>
     7   <xsl:variable name="subhmitree" select="ns:GetSubHMITree()"/>
    75                     <xsl:text> has wrong syntax of path section </xsl:text>
    75                     <xsl:text> has wrong syntax of path section </xsl:text>
    76                     <xsl:value-of select="$pathminmax"/>
    76                     <xsl:value-of select="$pathminmax"/>
    77                   </xsl:message>
    77                   </xsl:message>
    78                 </xsl:when>
    78                 </xsl:when>
    79               </xsl:choose>
    79               </xsl:choose>
    80               <xsl:choose>
    80               <xsl:if test="$indexed_hmitree">
    81                 <xsl:when test="regexp:test($path,'^\.[a-zA-Z0-9_]+$')">
    81                 <xsl:choose>
    82                   <xsl:attribute name="type">
    82                   <xsl:when test="regexp:test($path,'^\.[a-zA-Z0-9_]+$')">
    83                     <xsl:text>PAGE_LOCAL</xsl:text>
    83                     <xsl:attribute name="type">
    84                   </xsl:attribute>
    84                       <xsl:text>PAGE_LOCAL</xsl:text>
    85                 </xsl:when>
       
    86                 <xsl:when test="regexp:test($path,'^[a-zA-Z0-9_]+$')">
       
    87                   <xsl:attribute name="type">
       
    88                     <xsl:text>HMI_LOCAL</xsl:text>
       
    89                   </xsl:attribute>
       
    90                 </xsl:when>
       
    91                 <xsl:otherwise>
       
    92                   <xsl:variable name="item" select="$indexed_hmitree/*[@hmipath = $path]"/>
       
    93                   <xsl:variable name="pathtype" select="local-name($item)"/>
       
    94                   <xsl:if test="$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')">
       
    95                     <xsl:message terminate="yes">
       
    96                       <xsl:text>Widget id:</xsl:text>
       
    97                       <xsl:value-of select="$id"/>
       
    98                       <xsl:text> label:</xsl:text>
       
    99                       <xsl:value-of select="$label"/>
       
   100                       <xsl:text> path section </xsl:text>
       
   101                       <xsl:value-of select="$pathminmax"/>
       
   102                       <xsl:text> use min and max on non mumeric value</xsl:text>
       
   103                     </xsl:message>
       
   104                   </xsl:if>
       
   105                   <xsl:if test="count($item) = 1">
       
   106                     <xsl:attribute name="index">
       
   107                       <xsl:value-of select="$item/@index"/>
       
   108                     </xsl:attribute>
    85                     </xsl:attribute>
       
    86                   </xsl:when>
       
    87                   <xsl:when test="regexp:test($path,'^[a-zA-Z0-9_]+$')">
   109                     <xsl:attribute name="type">
    88                     <xsl:attribute name="type">
   110                       <xsl:value-of select="$pathtype"/>
    89                       <xsl:text>HMI_LOCAL</xsl:text>
   111                     </xsl:attribute>
    90                     </xsl:attribute>
   112                   </xsl:if>
    91                   </xsl:when>
   113                 </xsl:otherwise>
    92                   <xsl:otherwise>
   114               </xsl:choose>
    93                     <xsl:variable name="item" select="$indexed_hmitree/*[@hmipath = $path]"/>
       
    94                     <xsl:variable name="pathtype" select="local-name($item)"/>
       
    95                     <xsl:if test="$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')">
       
    96                       <xsl:message terminate="yes">
       
    97                         <xsl:text>Widget id:</xsl:text>
       
    98                         <xsl:value-of select="$id"/>
       
    99                         <xsl:text> label:</xsl:text>
       
   100                         <xsl:value-of select="$label"/>
       
   101                         <xsl:text> path section </xsl:text>
       
   102                         <xsl:value-of select="$pathminmax"/>
       
   103                         <xsl:text> use min and max on non mumeric value</xsl:text>
       
   104                       </xsl:message>
       
   105                     </xsl:if>
       
   106                     <xsl:if test="count($item) = 1">
       
   107                       <xsl:attribute name="index">
       
   108                         <xsl:value-of select="$item/@index"/>
       
   109                       </xsl:attribute>
       
   110                       <xsl:attribute name="type">
       
   111                         <xsl:value-of select="$pathtype"/>
       
   112                       </xsl:attribute>
       
   113                     </xsl:if>
       
   114                   </xsl:otherwise>
       
   115                 </xsl:choose>
       
   116               </xsl:if>
   115             </path>
   117             </path>
   116           </xsl:if>
   118           </xsl:if>
   117         </xsl:for-each>
   119         </xsl:for-each>
   118       </widget>
   120       </widget>
   119     </xsl:if>
   121     </xsl:if>
       
   122   </xsl:template>
       
   123   <xsl:template mode="genlabel" match="arg">
       
   124     <xsl:text>:</xsl:text>
       
   125     <xsl:value-of select="@value"/>
       
   126   </xsl:template>
       
   127   <xsl:template mode="genlabel" match="path">
       
   128     <xsl:text>@</xsl:text>
       
   129     <xsl:value-of select="@value"/>
       
   130     <xsl:if test="string-length(@min)&gt;0 or string-length(@max)&gt;0">
       
   131       <xsl:text>:</xsl:text>
       
   132       <xsl:value-of select="@min"/>
       
   133       <xsl:text>:</xsl:text>
       
   134       <xsl:value-of select="@max"/>
       
   135     </xsl:if>
       
   136   </xsl:template>
       
   137   <xsl:template mode="genlabel" match="widget">
       
   138     <xsl:text>HMI:</xsl:text>
       
   139     <xsl:value-of select="@type"/>
       
   140     <xsl:apply-templates mode="genlabel" select="arg"/>
       
   141     <xsl:apply-templates mode="genlabel" select="path"/>
   120   </xsl:template>
   142   </xsl:template>
   121   <xsl:variable name="_parsed_widgets">
   143   <xsl:variable name="_parsed_widgets">
   122     <xsl:apply-templates mode="parselabel" select="$hmi_elements"/>
   144     <xsl:apply-templates mode="parselabel" select="$hmi_elements"/>
   123   </xsl:variable>
   145   </xsl:variable>
   124   <xsl:variable name="parsed_widgets" select="exsl:node-set($_parsed_widgets)"/>
   146   <xsl:variable name="parsed_widgets" select="exsl:node-set($_parsed_widgets)"/>
   125   <xsl:variable name="selected_node_type" select="local-name($subhmitree)"/>
   147   <xsl:variable name="selected_node_type" select="local-name($subhmitree)"/>
   126   <xsl:variable name="svg_widget" select="$parsed_widgets/widget[1]"/>
   148   <xsl:variable name="svg_widget" select="$parsed_widgets/widget[1]"/>
   127   <xsl:variable name="svg_widget_type" select="$svg_widget/@type"/>
   149   <xsl:variable name="svg_widget_type" select="$svg_widget/@type"/>
   128   <xsl:variable name="svg_widget_path" select="$svg_widget/@path"/>
   150   <xsl:variable name="svg_widget_path" select="$svg_widget/@path"/>
   129   <xsl:variable name="svg_widget_count" select="count($parsed_widgets/widget)"/>
   151   <xsl:variable name="svg_widget_count" select="count($parsed_widgets/widget)"/>
       
   152   <xsl:template mode="replace_path" match="@* | node()">
       
   153     <xsl:copy>
       
   154       <xsl:apply-templates mode="replace_path" select="@* | node()"/>
       
   155     </xsl:copy>
       
   156   </xsl:template>
       
   157   <xsl:template mode="replace_path" match="path/@value">
       
   158     <xsl:attribute name="value">
       
   159       <xsl:value-of select="$hmi_path"/>
       
   160     </xsl:attribute>
       
   161   </xsl:template>
   130   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@*">
   162   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@*">
   131     <xsl:copy/>
   163     <xsl:copy/>
   132   </xsl:template>
   164   </xsl:template>
   133   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@inkscape:label[starts-with(., 'HMI:')]">
   165   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@inkscape:label[starts-with(., 'HMI:')]"/>
   134     <xsl:attribute name="inkscape:label">
       
   135       <xsl:value-of select="substring-before(., '@')"/>
       
   136       <xsl:text>@</xsl:text>
       
   137       <xsl:value-of select="$hmi_path"/>
       
   138     </xsl:attribute>
       
   139   </xsl:template>
       
   140   <xsl:template mode="inline_svg" match="node()">
   166   <xsl:template mode="inline_svg" match="node()">
   141     <xsl:copy>
   167     <xsl:copy>
       
   168       <xsl:if test="@id = $svg_widget/@id">
       
   169         <xsl:variable name="substituted_widget">
       
   170           <xsl:apply-templates mode="replace_path" select="$svg_widget"/>
       
   171         </xsl:variable>
       
   172         <xsl:variable name="substituted_widget_ns" select="exsl:node-set($substituted_widget)"/>
       
   173         <xsl:variable name="new_label">
       
   174           <xsl:apply-templates mode="genlabel" select="$substituted_widget_ns"/>
       
   175         </xsl:variable>
       
   176         <xsl:attribute name="inkscape:label">
       
   177           <xsl:value-of select="$new_label"/>
       
   178         </xsl:attribute>
       
   179       </xsl:if>
   142       <xsl:apply-templates mode="inline_svg" select="@* | node()"/>
   180       <xsl:apply-templates mode="inline_svg" select="@* | node()"/>
   143     </xsl:copy>
   181     </xsl:copy>
   144   </xsl:template>
   182   </xsl:template>
   145   <xsl:variable name="NODES_TYPES" select="str:split('HMI_ROOT HMI_NODE')"/>
   183   <xsl:variable name="NODES_TYPES" select="str:split('HMI_ROOT HMI_NODE')"/>
   146   <xsl:variable name="HMI_NODES_COMPAT" select="str:split('Page Jump Foreach')"/>
   184   <xsl:variable name="HMI_NODES_COMPAT" select="str:split('Page Jump Foreach')"/>