svghmi/gen_dnd_widget_svg.xslt
branchsvghmi
changeset 3223 061796d9855e
parent 3222 6adeeb16ac3e
child 3224 507dd7bc8cb5
equal deleted inserted replaced
3222:6adeeb16ac3e 3223:061796d9855e
     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: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:variable name="svg" select="/svg:svg"/>
     5   <xsl:variable name="svg" select="/svg:svg"/>
     5   <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:')]"/>
     6   <xsl:variable name="subhmitree" select="ns:GetSubHMITree()"/>
     7   <xsl:variable name="subhmitree" select="ns:GetSubHMITree()"/>
     7   <xsl:variable name="indexed_hmitree" select="/.."/>
     8   <xsl:variable name="indexed_hmitree" select="/.."/>
     8   <xsl:template mode="parselabel" match="*">
     9   <xsl:template mode="parselabel" match="*">
   119   </xsl:template>
   120   </xsl:template>
   120   <xsl:variable name="_parsed_widgets">
   121   <xsl:variable name="_parsed_widgets">
   121     <xsl:apply-templates mode="parselabel" select="$hmi_elements"/>
   122     <xsl:apply-templates mode="parselabel" select="$hmi_elements"/>
   122   </xsl:variable>
   123   </xsl:variable>
   123   <xsl:variable name="parsed_widgets" select="exsl:node-set($_parsed_widgets)"/>
   124   <xsl:variable name="parsed_widgets" select="exsl:node-set($_parsed_widgets)"/>
       
   125   <xsl:variable name="selected_node_type" select="local-name($subhmitree)"/>
       
   126   <xsl:variable name="svg_widget" select="$parsed_widgets/widget[1]"/>
       
   127   <xsl:variable name="svg_widget_type" select="$svg_widget/@type"/>
       
   128   <xsl:variable name="svg_widget_path" select="$svg_widget/@path"/>
       
   129   <xsl:variable name="svg_widget_count" select="count($parsed_widgets/widget)"/>
   124   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@*">
   130   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@*">
       
   131     <xsl:copy/>
       
   132   </xsl:template>
       
   133   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@inkscape:label[starts-with(., 'HMI:')]">
   125     <xsl:copy/>
   134     <xsl:copy/>
   126   </xsl:template>
   135   </xsl:template>
   127   <xsl:template mode="inline_svg" match="node()">
   136   <xsl:template mode="inline_svg" match="node()">
   128     <xsl:copy>
   137     <xsl:copy>
   129       <xsl:apply-templates mode="inline_svg" select="@* | node()"/>
   138       <xsl:apply-templates mode="inline_svg" select="@* | node()"/>
   133   <xsl:variable name="HMI_NODES_COMPAT" select="str:split('Page Jump Foreach')"/>
   142   <xsl:variable name="HMI_NODES_COMPAT" select="str:split('Page Jump Foreach')"/>
   134   <xsl:template match="/">
   143   <xsl:template match="/">
   135     <xsl:comment>
   144     <xsl:comment>
   136       <xsl:text>Widget dropped in Inkscape from Beremiz</xsl:text>
   145       <xsl:text>Widget dropped in Inkscape from Beremiz</xsl:text>
   137     </xsl:comment>
   146     </xsl:comment>
   138     <xsl:variable name="selected_node_type" select="local-name($subhmitree)"/>
       
   139     <xsl:variable name="svg_widget_type" select="$parsed_widgets/widget[1]/@type"/>
       
   140     <xsl:variable name="svg_widget_count" select="count($parsed_widgets/widget)"/>
       
   141     <xsl:choose>
   147     <xsl:choose>
   142       <xsl:when test="$svg_widget_count &lt; 1">
   148       <xsl:when test="$svg_widget_count &lt; 1">
   143         <xsl:message terminate="yes">
   149         <xsl:message terminate="yes">
   144           <xsl:text>No widget detected on selected SVG</xsl:text>
   150           <xsl:text>No widget detected on selected SVG</xsl:text>
   145         </xsl:message>
   151         </xsl:message>
   149           <xsl:text>Multiple widget DnD not yet supported</xsl:text>
   155           <xsl:text>Multiple widget DnD not yet supported</xsl:text>
   150         </xsl:message>
   156         </xsl:message>
   151       </xsl:when>
   157       </xsl:when>
   152       <xsl:when test="$selected_node_type = $NODES_TYPES and                     not($svg_widget_type = $HMI_NODES_COMPAT)">
   158       <xsl:when test="$selected_node_type = $NODES_TYPES and                     not($svg_widget_type = $HMI_NODES_COMPAT)">
   153         <xsl:message terminate="yes">
   159         <xsl:message terminate="yes">
   154           <xsl:text>Widget incopatible with selected HMI tree node</xsl:text>
   160           <xsl:text>Widget incompatible with selected HMI tree node</xsl:text>
   155         </xsl:message>
   161         </xsl:message>
   156       </xsl:when>
   162       </xsl:when>
   157     </xsl:choose>
   163     </xsl:choose>
   158     <xsl:variable name="testmsg">
   164     <xsl:variable name="testmsg">
       
   165       <msg>
       
   166         <xsl:value-of select="$hmi_path"/>
       
   167       </msg>
   159       <msg>
   168       <msg>
   160         <xsl:value-of select="$selected_node_type"/>
   169         <xsl:value-of select="$selected_node_type"/>
   161       </msg>
   170       </msg>
   162       <msg>
   171       <msg>
   163         <xsl:value-of select="$svg_widget_type"/>
   172         <xsl:value-of select="$svg_widget_type"/>