lvDCOM
An EPICS support module to export LabVIEW values as process variables
lvstrings2input.xsl

XSLT stylesheet to generate an initial lvinput.xml file from a controls.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!--
########### SVN repository information ###################
# $LastChangedDate: 2013-09-16 15:27:50 +0100 (Mon, 16 Sep 2013) $
# $LastChangedBy: faa59 $
# $LastChangedRevision: 433 $
# $HeadURL: https://svn.isis.rl.ac.uk/EPICS/trunk/ISIS/lvDCOM/lvDCOMApp/src/lvstrings2input.xsl $
########### SVN repository information ###################
Usage: xsltproc lvstrings2input.xsl lvstrings.xml > lvinput.xml
lvstrings.xml is the output of ExportVIStrings() from LabVIEW, but has also
been processed by the fix_xml.cmd script (as the raw output of ExportVIStrings() is not valid XML)
To run ExportVIStrings() interactively, go to "Tools -> Advanced -> Export Strings..." from the LabVIEW VI menu bar
@file lvstrings2input.xsl Process output of LabVIEW ExportVIStrings() to generate an XML configuration file for lvDCOM
@author Freddie Akeroyd, STFC ISIS Facility, UK
-->
<xsl:stylesheet
version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:lvdcom="http://epics.isis.rl.ac.uk/lvDCOMinput/1.0">
<xsl:output method="xml" indent="yes" version="1.0" encoding="UTF-8"/>
<xsl:template match="/VI">
<xsl:comment>Generated by $Id: lvstrings2input.xsl 433 2013-09-16 14:27:50Z faa59 $</xsl:comment>
<xsl:variable name="vi_name" select="@name" />
<xsl:element name="lvinput">
<xsl:attribute name="xmlns">http://epics.isis.rl.ac.uk/lvDCOMinput/1.0</xsl:attribute>
<xsl:attribute name="xsi:schemaLocation">http://epics.isis.rl.ac.uk/lvDCOMinput/1.0 lvDCOMinput.xsd</xsl:attribute>
<xsl:element name="extint">
<xsl:attribute name="path">c:/LabVIEW Modules/Common/External Interface/External Interface.llb/External Interface - Set Value.vi</xsl:attribute>
</xsl:element>
<xsl:element name="section" >
<xsl:attribute name="name">frontpanel</xsl:attribute>
<xsl:element name="vi">
<xsl:attribute name="path"><xsl:value-of select="$vi_name"/></xsl:attribute>
<xsl:apply-templates select="CONTENT" />
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="CONTENT">
<xsl:apply-templates select="CONTROL" />
</xsl:template>
<xsl:template match="CONTROL">
<xsl:variable name="vartype" select="@type" />
<xsl:variable name="control_type">
<xsl:call-template name="convertLVType">
<xsl:with-param name="vartype" select="$vartype" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="control_id" select="@ID" />
<xsl:variable name="control_name" select="@name" />
<xsl:variable name="param_name" select="translate($control_name,' ', '_')" />
<xsl:choose>
<xsl:when test="$control_type != 'invalid'">
<xsl:element name="param">
<xsl:attribute name="name"><xsl:value-of select="$param_name"/></xsl:attribute>
<xsl:attribute name="type"><xsl:value-of select="$control_type"/></xsl:attribute>
<xsl:if test="$control_type = 'ring'"><xsl:call-template name="extractRingText"/> </xsl:if>
<xsl:if test="$control_type = 'enum'"><xsl:call-template name="extractRingText"/> </xsl:if>
<xsl:if test="$control_type = 'boolean'"><xsl:call-template name="extractBooleanText"/> </xsl:if>
<xsl:element name="read">
<xsl:attribute name="method">GCV</xsl:attribute>
<xsl:attribute name="target"><xsl:value-of select="$control_name"/></xsl:attribute>
</xsl:element>
<xsl:element name="set">
<xsl:attribute name="method">SCV</xsl:attribute>
<xsl:attribute name="extint">false</xsl:attribute>
<xsl:attribute name="target"><xsl:value-of select="$control_name"/></xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:comment>Ignoring <xsl:value-of select="$control_name"/> as invalid type <xsl:value-of select="$vartype"/></xsl:comment>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="extractRingText">
<xsl:element name="items">
<xsl:variable name="n" select="count(.//PARTS/PART[@type='Ring Text']/MLABEL/STRINGS/STRING)" />
<xsl:choose>
<xsl:when test="$n > 0">
<xsl:comment>Ring Names extracted from LabVIEW, values were autogenerated assuming they started at 0 and had no gaps, so may need to be manually modified</xsl:comment>
<xsl:for-each select=".//PARTS/PART[@type='Ring Text']/MLABEL/STRINGS/STRING">
<xsl:element name="item">
<xsl:attribute name="name"><xsl:value-of select="."/></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="position()-1"/></xsl:attribute>
</xsl:element>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:comment>Ring/Enum names could not be extracted from LabVIEW - you will need to add them manually if required</xsl:comment>
<xsl:element name="item">
<xsl:attribute name="name">Value-0</xsl:attribute>
<xsl:attribute name="value">0</xsl:attribute>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:template>
<xsl:template name="extractBooleanText">
<xsl:element name="items">
<xsl:for-each select=".//PARTS/PART[@type='Boolean Text']/MLABEL/STRINGS/STRING">
<xsl:element name="item">
<xsl:attribute name="name"><xsl:value-of select="."/></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="position()-1"/></xsl:attribute>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template name="convertLVType">
<xsl:param name="vartype" />
<xsl:choose>
<xsl:when test="$vartype = 'Numeric'">float64</xsl:when>
<xsl:when test="$vartype = 'String'">string</xsl:when>
<xsl:when test="$vartype = 'Boolean'">boolean</xsl:when>
<xsl:when test="$vartype = 'Enum'">enum</xsl:when>
<xsl:when test="$vartype = 'Ring'">ring</xsl:when>
<xsl:when test="$vartype = 'Type Definition'">
<xsl:call-template name="convertLVType">
<xsl:with-param name="vartype" select="PARTS/PART/CONTROL[1]/@type" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>invalid</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<!--
/CONTENT/CONTROL/@type Numeric(ID=80) String(ID=81) Array(ID=82) Boolean(ID=79) Cluster "Radio Buttons" "Ring" "Listbox" "Enum" "Type Definition"
/CONTENT/CONTROL/@name
if array, /CONTENT/CONTROL/CONTENT/CONTROL/@type Numeric
-->