Page 1 of 1

Working on exported XML files

Posted: Mon Jul 28, 2014 6:44 pm
by wojtekw
Hello,

Is there a way to edit values in XML file using table view?

One of my (non-XML) programs exports project into an XML file like this:

Code: Select all


<listIndicator name="ListIndicator1" height="18" width="248" left="32" top="94" visible="true" wallpaper="false" isReferenceObject="false" backColor="black" borderStyle="line" borderUsesBackColor="false" borderWidth="1" selectionForeColor="black" selectionBackColor="black" description="" borderColor="black" patternColor="white" patternStyle="none" blink="false" triggerType="value" fontFamily="PV 8x16" fontSize="12" bold="false" italic="false" underline="false" strikethrough="false" captionTruncate="character" setLastStateId="144">
<states>
<state stateId="0" value="0">
<caption caption="F01_480VAC Segment 1" color="#CECBCE" backColor="black" backStyle="transparent" alignment="left" blink="false"/>
</state>
<state stateId="1" value="-127">
<caption caption="F10_120VAC for PLC" color="#CECBCE" backColor="black" backStyle="transparent" alignment="left" blink="false"/>
</state>
<state stateId="2" value="-1">
<caption caption="F11_24VDC for PanelView" color="#CECBCE" backColor="black" backStyle="transparent" alignment="left" blink="false"/>
</state>
..... more states
</states>
</listIndicator>
Is it possible to use oxygen to edit something like that in an grid-like view in form of:

Code: Select all


stateId | value | caption | color | backColor | backStyle | alignment | blink
0 | 0 | F01_480*| CECBCE| black | transpar* | left | false
....
This data is a screen from operator panel in FTView ME Studio exported to XML.
This will allow me to work on large objects with 100+ states. Mostly I will have to overwrite captions from another project. In previous version of this program (PanelBuilder) you could edit objects in excel like list just like I listed right above and I would get my captions in excel, copy whole range of captions and paste into that list. In new version, you have to edit one by one and XML export is the only way to possibly automate this.

If anybody has an idea how to do it, I will really appreciate it.

Re: Working on exported XML files

Posted: Wed Jul 30, 2014 5:53 pm
by adrian
Hi,

I'm including here the stylesheets that I provided in private in case anyone else has a document structured similarly (nested elements) and wants to use the Grid mode.

So, for a nested element like state/caption this stylesheet produces an intermediary XML file that merges all the attributes from 'caption' in the state element. This intermediary XML file allows you to use the Grid mode on the tabular structure.
Both these stylesheets are based on a copy stylesheet (Oxygen/samples/xhtml/copy.xsl) from the Oxygen sample files.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<!-- Match document -->
<xsl:template match="/">
<xsl:apply-templates mode="copy" select="."/>
</xsl:template>
<!-- Deep copy template -->
<xsl:template match="*|text()|@*" mode="copy">
<xsl:copy>
<xsl:apply-templates mode="copy" select="@*"/>
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:template>
<xsl:template match="state" mode="copy">
<xsl:copy>
<xsl:apply-templates mode="copy" select="@*"/>
<xsl:apply-templates select="caption/@*" mode="copy"/>
</xsl:copy>
</xsl:template>
<!-- Handle default matching -->
<xsl:template match="*"/>
</xsl:stylesheet>
After processing the document in Grid mode, this second stylesheet can be applied to extract the attributes from 'state' back into the original structure with a nested 'caption' element. This simply copies the 'stateId' and 'value' attributes into the 'state' element and moves all the other attributes into 'caption':

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<!-- Match document -->
<xsl:template match="/">
<xsl:apply-templates mode="copy" select="."/>
</xsl:template>
<!-- Deep copy template -->
<xsl:template match="*|text()|@*" mode="copy">
<xsl:copy>
<xsl:apply-templates mode="copy" select="@*"/>
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:template>
<xsl:template match="state" mode="copy">
<xsl:copy>
<xsl:apply-templates mode="copy" select="@stateId|@value"/>
<caption>
<xsl:apply-templates mode="copy" select="@*[not(local-name(.)='stateId' or local-name(.)='value')]"/>
</caption>
</xsl:copy>
</xsl:template>
<!-- Handle default matching -->
<xsl:template match="*"/>
</xsl:stylesheet>
Regards,
Adrian