Update column names in XSY module.
This commit is contained in:
@@ -1,30 +1,40 @@
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<!--
|
||||
<!--
|
||||
Flatten a ControlExpert XSY file so that it can be read by pandas.
|
||||
|
||||
Copyright 2026 Prime Controls. All rights reserved.
|
||||
-->
|
||||
<xsl:output encoding="utf8" method="xml" omit-xml-declaration="no" indent="yes"/>
|
||||
<xsl:output encoding="utf8" method="xml" omit-xml-declaration="no" indent="yes" />
|
||||
|
||||
<xsl:template match="/VariablesExchangeFile">
|
||||
<xsl:copy>
|
||||
<xsl:apply-templates select="dataBlock"/>
|
||||
<xsl:apply-templates select="dataBlock" />
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="dataBlock">
|
||||
<xsl:apply-templates select="variables"/>
|
||||
<xsl:apply-templates select="variables" />
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="variables">
|
||||
<xsl:copy>
|
||||
<name><xsl:value-of select="@name"/></name>
|
||||
<type><xsl:value-of select="@typeName"/></type>
|
||||
<address><xsl:value-of select="@topologicalAddress"/></address>
|
||||
<comment><xsl:value-of select="comment"/></comment>
|
||||
<parent/>
|
||||
<bitrank/>
|
||||
<save><xsl:value-of select="attribute/@Save"/></save>
|
||||
<tagname>
|
||||
<xsl:value-of select="@name" />
|
||||
</tagname>
|
||||
<type>
|
||||
<xsl:value-of select="@typeName" />
|
||||
</type>
|
||||
<address>
|
||||
<xsl:value-of select="@topologicalAddress" />
|
||||
</address>
|
||||
<comment>
|
||||
<xsl:value-of select="comment" />
|
||||
</comment>
|
||||
<parent />
|
||||
<bitrank />
|
||||
<save>
|
||||
<xsl:value-of select="attribute/@Save" />
|
||||
</save>
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<!--
|
||||
<!--
|
||||
Flatten a ControlExpert XSY file so that it can be read by pandas.
|
||||
|
||||
Copyright 2026 Prime Controls. All rights reserved.
|
||||
@@ -8,41 +8,49 @@
|
||||
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'" />
|
||||
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
|
||||
|
||||
<xsl:output encoding="utf8" method="xml" omit-xml-declaration="no" indent="yes"/>
|
||||
<xsl:output encoding="utf8" method="xml" omit-xml-declaration="no" indent="yes" />
|
||||
|
||||
<xsl:template match="/VariablesExchangeFile">
|
||||
<xsl:copy>
|
||||
<xsl:apply-templates select="DDTSource"/>
|
||||
<xsl:apply-templates select="FBSource"/>
|
||||
<xsl:apply-templates select="DDTSource" />
|
||||
<xsl:apply-templates select="FBSource" />
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="DDTSource">
|
||||
<xsl:apply-templates select="structure/variables"/>
|
||||
<xsl:apply-templates select="structure/variables" />
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="structure/variables">
|
||||
<xsl:copy>
|
||||
<name><xsl:value-of select="@name"/></name>
|
||||
<type><xsl:value-of select="translate(@typeName, $lowercase, $uppercase)"/></type>
|
||||
<address/>
|
||||
<comment><xsl:value-of select="../../comment"/>: <xsl:value-of select="comment"/></comment>
|
||||
<parent><xsl:value-of select="translate(../../@DDTName, $lowercase, $uppercase)"/></parent>
|
||||
<tagname>
|
||||
<xsl:value-of select="@name" />
|
||||
</tagname>
|
||||
<type>
|
||||
<xsl:value-of select="translate(@typeName, $lowercase, $uppercase)" />
|
||||
</type>
|
||||
<address />
|
||||
<comment><xsl:value-of select="../../comment" />: <xsl:value-of select="comment" /></comment>
|
||||
<parent>
|
||||
<xsl:value-of select="translate(../../@DDTName, $lowercase, $uppercase)" />
|
||||
</parent>
|
||||
<bitrank>
|
||||
<xsl:for-each select="attribute">
|
||||
<xsl:if test="@name='ExtractBit'">
|
||||
<xsl:value-of select="@value"/>
|
||||
<xsl:value-of select="@value" />
|
||||
</xsl:if>
|
||||
</xsl:for-each>
|
||||
</bitrank>
|
||||
<save/>
|
||||
<save />
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="FBSource">
|
||||
<xsl:copy>
|
||||
<name>NULL</name>
|
||||
<parent><xsl:value-of select="translate(@nameOfFBType, $lowercase, $uppercase)"/></parent>
|
||||
<parent>
|
||||
<xsl:value-of select="translate(@nameOfFBType, $lowercase, $uppercase)" />
|
||||
</parent>
|
||||
<type>DFB</type>
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
@@ -405,15 +405,15 @@ class XSY:
|
||||
"""Compile a cross-joined and filtered DataBlock by combining the
|
||||
columns from the datablock with the columns from the definitions."""
|
||||
datablock_compiled = pd.DataFrame()
|
||||
datablock_compiled["name"] = datablock.apply(
|
||||
lambda row: f"{row['name']}.{row['name_def']}", axis=1
|
||||
datablock_compiled["tagname"] = datablock.apply(
|
||||
lambda row: f"{row['tagname']}.{row['tagname_def']}", axis=1
|
||||
)
|
||||
datablock_compiled["parent"] = ""
|
||||
datablock_compiled["type"] = datablock["type_def"]
|
||||
datablock_compiled["address"] = datablock.apply(
|
||||
lambda row: self._combine_addresses(row),
|
||||
axis=1,
|
||||
)
|
||||
datablock_compiled["parent"] = ""
|
||||
datablock_compiled["bitrank"] = datablock["bitrank_def"]
|
||||
datablock_compiled["save"] = datablock["save"]
|
||||
datablock_compiled["comment"] = datablock.apply(
|
||||
@@ -573,7 +573,12 @@ class XSYReader:
|
||||
self.definitions_ss_path = definitions_ss_path
|
||||
self.even_addresses = even_addresses
|
||||
|
||||
def read(self, path: Traversable, expand: bool = True) -> XSYBlock:
|
||||
def read(
|
||||
self,
|
||||
path: Traversable,
|
||||
expand: bool = True,
|
||||
converters=None,
|
||||
) -> XSYBlock:
|
||||
"""Read the dataBlock and definitions of an XSY file into an XSY
|
||||
object.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user