ISIS Logo
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$
# $LastChangedBy$
# $LastChangedRevision$
# $HeadURL$
########### 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>Initially generated by $Id$ </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:comment>Full path to external interface vi used for triggering LabVIEW events when extint="true" below </xsl:comment>
<xsl:element name="extint">
<xsl:attribute name="path">$(TOP)/lvDCOMApp/src/extint/Main/Library/External Interface - Set Value.vi</xsl:attribute>
</xsl:element>
<xsl:comment>Definition of a configSection, the second argument of the IOC lvDCOMConfigure() command </xsl:comment>
<xsl:element name="section" >
<xsl:attribute name="name">frontpanel</xsl:attribute>
<xsl:comment>TODO: edit path attribute in &lt;vi /&gt; to contain a full absolute path, you can also use any EPICS macro known to the IOC e.g. $(TOP) </xsl:comment>
<xsl:element name="vi">
<xsl:attribute name="path"><xsl:value-of select="$vi_name"/></xsl:attribute>
<xsl:comment>The &lt;param /&gt; maps an asyn driver parameter "name" (referenced in the EPICS .db) to the LabVIEW item "target" </xsl:comment>
<xsl:comment>TODO: set extint="true" for controls that either need LabVIEW events triggering when they are written to
or have limits specified on the labview control that need to be honoured. There is no harm
other than a small performance penalty in setting it to true</xsl:comment>
<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,' ()[]${}#~@?!%&lt;>&amp;', '_________________')" />
<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 LabVIEW control &quot;<xsl:value-of select="$control_name"/>&quot; as it has invalid type &quot;<xsl:value-of select="$vartype"/>&quot;</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>TODO: Ring Names extracted from LabVIEW, values were autogenerated assuming they started at 0 with 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>TODO: 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
-->
Copyright © 2013 Science and Technology Facilities Council | Generated by   doxygen 1.8.5