svghmi/gen_dnd_widget_svg.xslt
branchsvghmi
changeset 3234 f2bfb047d0e6
parent 3229 c5be4fd425e7
child 3264 51645afeded9
equal deleted inserted replaced
3233:315f17e74ef5 3234:f2bfb047d0e6
     1 <?xml version="1.0"?>
     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: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">
     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: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"/>
       
     6   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
     5   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
     7   <xsl:variable name="subhmitree" select="ns:GetSubHMITree()"/>
     6   <xsl:variable name="subhmitree" select="ns:GetSubHMITree()"/>
     8   <xsl:variable name="indexed_hmitree" select="/.."/>
     7   <xsl:variable name="indexed_hmitree" select="/.."/>
       
     8   <xsl:variable name="pathregex" select="'^([^\[,]+)(\[[^\]]+\])?([\d,]*)$'"/>
     9   <xsl:template mode="parselabel" match="*">
     9   <xsl:template mode="parselabel" match="*">
    10     <xsl:variable name="label" select="@inkscape:label"/>
    10     <xsl:variable name="label" select="@inkscape:label"/>
    11     <xsl:variable name="id" select="@id"/>
    11     <xsl:variable name="id" select="@id"/>
    12     <xsl:variable name="description" select="substring-after($label,'HMI:')"/>
    12     <xsl:variable name="description" select="substring-after($label,'HMI:')"/>
    13     <xsl:variable name="_args" select="substring-before($description,'@')"/>
    13     <xsl:variable name="_args" select="substring-before($description,'@')"/>
    49         </xsl:for-each>
    49         </xsl:for-each>
    50         <xsl:variable name="paths" select="substring-after($description,'@')"/>
    50         <xsl:variable name="paths" select="substring-after($description,'@')"/>
    51         <xsl:for-each select="str:split($paths, '@')">
    51         <xsl:for-each select="str:split($paths, '@')">
    52           <xsl:if test="string-length(.) &gt; 0">
    52           <xsl:if test="string-length(.) &gt; 0">
    53             <path>
    53             <path>
    54               <xsl:variable name="pathminmax" select="str:split(.,',')"/>
    54               <xsl:variable name="path_match" select="regexp:match(.,$pathregex)"/>
    55               <xsl:variable name="path" select="$pathminmax[1]"/>
    55               <xsl:variable name="pathminmax" select="str:split($path_match[4],',')"/>
       
    56               <xsl:variable name="path" select="$path_match[2]"/>
       
    57               <xsl:variable name="path_accepts" select="$path_match[3]"/>
    56               <xsl:variable name="pathminmaxcount" select="count($pathminmax)"/>
    58               <xsl:variable name="pathminmaxcount" select="count($pathminmax)"/>
    57               <xsl:attribute name="value">
    59               <xsl:attribute name="value">
    58                 <xsl:value-of select="$path"/>
    60                 <xsl:value-of select="$path"/>
    59               </xsl:attribute>
    61               </xsl:attribute>
       
    62               <xsl:if test="string-length($path_accepts)">
       
    63                 <xsl:attribute name="accepts">
       
    64                   <xsl:value-of select="$path_accepts"/>
       
    65                 </xsl:attribute>
       
    66               </xsl:if>
    60               <xsl:choose>
    67               <xsl:choose>
    61                 <xsl:when test="$pathminmaxcount = 3">
    68                 <xsl:when test="$pathminmaxcount = 2">
    62                   <xsl:attribute name="min">
    69                   <xsl:attribute name="min">
       
    70                     <xsl:value-of select="$pathminmax[1]"/>
       
    71                   </xsl:attribute>
       
    72                   <xsl:attribute name="max">
    63                     <xsl:value-of select="$pathminmax[2]"/>
    73                     <xsl:value-of select="$pathminmax[2]"/>
    64                   </xsl:attribute>
    74                   </xsl:attribute>
    65                   <xsl:attribute name="max">
       
    66                     <xsl:value-of select="$pathminmax[3]"/>
       
    67                   </xsl:attribute>
       
    68                 </xsl:when>
    75                 </xsl:when>
    69                 <xsl:when test="$pathminmaxcount = 2">
    76                 <xsl:when test="$pathminmaxcount = 1 or $pathminmaxcount &gt; 2">
    70                   <xsl:message terminate="yes">
    77                   <xsl:message terminate="yes">
    71                     <xsl:text>Widget id:</xsl:text>
    78                     <xsl:text>Widget id:</xsl:text>
    72                     <xsl:value-of select="$id"/>
    79                     <xsl:value-of select="$id"/>
    73                     <xsl:text> label:</xsl:text>
    80                     <xsl:text> label:</xsl:text>
    74                     <xsl:value-of select="$label"/>
    81                     <xsl:value-of select="$label"/>
   126   </xsl:template>
   133   </xsl:template>
   127   <xsl:template mode="genlabel" match="path">
   134   <xsl:template mode="genlabel" match="path">
   128     <xsl:text>@</xsl:text>
   135     <xsl:text>@</xsl:text>
   129     <xsl:value-of select="@value"/>
   136     <xsl:value-of select="@value"/>
   130     <xsl:if test="string-length(@min)&gt;0 or string-length(@max)&gt;0">
   137     <xsl:if test="string-length(@min)&gt;0 or string-length(@max)&gt;0">
   131       <xsl:text>:</xsl:text>
   138       <xsl:text>,</xsl:text>
   132       <xsl:value-of select="@min"/>
   139       <xsl:value-of select="@min"/>
   133       <xsl:text>:</xsl:text>
   140       <xsl:text>,</xsl:text>
   134       <xsl:value-of select="@max"/>
   141       <xsl:value-of select="@max"/>
   135     </xsl:if>
   142     </xsl:if>
   136   </xsl:template>
   143   </xsl:template>
   137   <xsl:template mode="genlabel" match="widget">
   144   <xsl:template mode="genlabel" match="widget">
   138     <xsl:text>HMI:</xsl:text>
   145     <xsl:text>HMI:</xsl:text>
   212       </msg>
   219       </msg>
   213       <msg>
   220       <msg>
   214         <xsl:value-of select="$svg_widget_type"/>
   221         <xsl:value-of select="$svg_widget_type"/>
   215       </msg>
   222       </msg>
   216     </xsl:variable>
   223     </xsl:variable>
   217     <xsl:value-of select="ns:GiveDetails($testmsg)"/>
   224     <xsl:value-of select="ns:PassMessage($testmsg)"/>
   218     <xsl:apply-templates mode="inline_svg" select="/"/>
   225     <xsl:apply-templates mode="inline_svg" select="/"/>
   219   </xsl:template>
   226   </xsl:template>
   220 </xsl:stylesheet>
   227 </xsl:stylesheet>