svghmi/gen_dnd_widget_svg.xslt
branchsvghmi
changeset 3222 6adeeb16ac3e
parent 3221 3d307ad803ea
child 3223 061796d9855e
equal deleted inserted replaced
3221:3d307ad803ea 3222:6adeeb16ac3e
     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:variable name="svg" select="/svg:svg"/>
     4   <xsl:variable name="svg" select="/svg:svg"/>
     5   <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:')]"/>
       
     6   <xsl:variable name="subhmitree" select="ns:GetSubHMITree()"/>
       
     7   <xsl:variable name="indexed_hmitree" select="/.."/>
     6   <xsl:template mode="parselabel" match="*">
     8   <xsl:template mode="parselabel" match="*">
     7     <xsl:variable name="label" select="@inkscape:label"/>
     9     <xsl:variable name="label" select="@inkscape:label"/>
     8     <xsl:variable name="id" select="@id"/>
    10     <xsl:variable name="id" select="@id"/>
     9     <xsl:variable name="description" select="substring-after($label,'HMI:')"/>
    11     <xsl:variable name="description" select="substring-after($label,'HMI:')"/>
    10     <xsl:variable name="_args" select="substring-before($description,'@')"/>
    12     <xsl:variable name="_args" select="substring-before($description,'@')"/>
   113           </xsl:if>
   115           </xsl:if>
   114         </xsl:for-each>
   116         </xsl:for-each>
   115       </widget>
   117       </widget>
   116     </xsl:if>
   118     </xsl:if>
   117   </xsl:template>
   119   </xsl:template>
       
   120   <xsl:variable name="_parsed_widgets">
       
   121     <xsl:apply-templates mode="parselabel" select="$hmi_elements"/>
       
   122   </xsl:variable>
       
   123   <xsl:variable name="parsed_widgets" select="exsl:node-set($_parsed_widgets)"/>
   118   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@*">
   124   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@*">
   119     <xsl:copy/>
   125     <xsl:copy/>
   120   </xsl:template>
   126   </xsl:template>
   121   <xsl:template mode="inline_svg" match="node()">
   127   <xsl:template mode="inline_svg" match="node()">
   122     <xsl:copy>
   128     <xsl:copy>
   123       <xsl:apply-templates mode="inline_svg" select="@* | node()"/>
   129       <xsl:apply-templates mode="inline_svg" select="@* | node()"/>
   124     </xsl:copy>
   130     </xsl:copy>
   125   </xsl:template>
   131   </xsl:template>
       
   132   <xsl:variable name="NODES_TYPES" select="str:split('HMI_ROOT HMI_NODE')"/>
       
   133   <xsl:variable name="HMI_NODES_COMPAT" select="str:split('Page Jump Foreach')"/>
   126   <xsl:template match="/">
   134   <xsl:template match="/">
   127     <xsl:comment>
   135     <xsl:comment>
   128       <xsl:text>Widget dropped in Inkscape from Beremiz</xsl:text>
   136       <xsl:text>Widget dropped in Inkscape from Beremiz</xsl:text>
   129     </xsl:comment>
   137     </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>
       
   142       <xsl:when test="$svg_widget_count &lt; 1">
       
   143         <xsl:message terminate="yes">
       
   144           <xsl:text>No widget detected on selected SVG</xsl:text>
       
   145         </xsl:message>
       
   146       </xsl:when>
       
   147       <xsl:when test="$svg_widget_count &gt; 1">
       
   148         <xsl:message terminate="yes">
       
   149           <xsl:text>Multiple widget DnD not yet supported</xsl:text>
       
   150         </xsl:message>
       
   151       </xsl:when>
       
   152       <xsl:when test="$selected_node_type = $NODES_TYPES and                     not($svg_widget_type = $HMI_NODES_COMPAT)">
       
   153         <xsl:message terminate="yes">
       
   154           <xsl:text>Widget incopatible with selected HMI tree node</xsl:text>
       
   155         </xsl:message>
       
   156       </xsl:when>
       
   157     </xsl:choose>
       
   158     <xsl:variable name="testmsg">
       
   159       <msg>
       
   160         <xsl:value-of select="$selected_node_type"/>
       
   161       </msg>
       
   162       <msg>
       
   163         <xsl:value-of select="$svg_widget_type"/>
       
   164       </msg>
       
   165     </xsl:variable>
       
   166     <xsl:value-of select="ns:GiveDetails($testmsg)"/>
   130     <xsl:apply-templates mode="inline_svg" select="/"/>
   167     <xsl:apply-templates mode="inline_svg" select="/"/>
   131   </xsl:template>
   168   </xsl:template>
   132 </xsl:stylesheet>
   169 </xsl:stylesheet>