[Home] [By Thread] [By Date] [Recent Entries]
At 2012-08-22 12:21 -0400, Wendell Piez wrote:
Hi again, Ha! Okay ... I'll take back the problem for a solution. Mind you, having finally solved the issue (I think! Please tell me if I'm wrong!), I ended up not feeling strongly about using a function anywhere. Richard, given that groups are defined in the groups.xml file, where is the flexibility needed for a function? Isn't the flexibility found in the groups.xml file? I've taken what I think is a very time-saving approach, first finding the groups that are in the area, and only then walking over the area alarms comparing each to the found groups. That way I'm not re-finding the found groups for every alarm, which I think is what the function was doing. I just can't figure out where function flexibility is needed ... I cannot see what needs to be tweaked that isn't simply in the groups.xml file. A transcript is below of what I hope is helpful this time around. Please let me know where I may have misunderstood the requirements, especially for flexibility. I hope the embedded comments are helpful. Apologies, again, for having jumped to the wrong solution in my earlier post. . . . . . . . . . . . Ken ~/t/ftemp $ cat groups.xml
<groups>
<group id="group-1">
<alarm equipment="Frame 1 PSU 1"/>
<alarm equipment="Frame 1 PSU 2"/>
<alarm equipment="Fan Tray 1"/>
</group>
<group id="group-2">
<alarm equipment="1 Alarm"/>
<alarm equipment="2 Alarm"/>
<alarm equipment="3 Alarm"/>
</group>
<group id="group-3">
<alarm equipment="MDU X([0-9]{4}) Relay fail"/>
<alarm equipment="MDU X([0-9]{4}) Fuse fail"/>
</group></groups>~/t/ftemp $
~/t/ftemp $ cat richard.xml
<areas>
<area name="LAR 23">
<alarm equipment="1 Alarm"/>
<alarm equipment="3 Alarm"/>
<alarm equipment="MDU X2301 Relay fail"/>
<alarm equipment="2 Alarm"/>
<alarm equipment="MDU X2301 Fuse fail"/>
</area>
<area name="LAR 41">
<alarm equipment="MDU X4107 Relay fail"/>
<alarm equipment="MDU X4107 Fuse fail"/>
<alarm equipment="MDU X4108 Relay fail"/>
<alarm equipment="MDU X4108 Fuse fail"/>
<alarm equipment="Frame 1 PSU 1"/>
<alarm equipment="Frame 1 PSU 2"/>
<alarm equipment="Fan Tray 1"/>
</area>
<area name="LAR 51">
<alarm equipment="1 Alarm"/>
<alarm equipment="3 Alarm"/>
<alarm equipment="Frame 1 PSU 1"/>
<alarm equipment="Frame 1 PSU 2"/>
<alarm equipment="Fan Tray 1"/>
</area>
<area name="LAR 53">
<alarm equipment="1 Alarm"/>
<alarm equipment="2 Alarm"/>
<alarm equipment="Rack 5308 Power Fail Alarm"/>
<alarm equipment="Rack 5309 Power Fail Alarm"/>
<alarm equipment="3 Alarm"/>
</area>
<area name="LAR63">
<alarm equipment="MDU X6311 Relay fail"/>
<alarm equipment="MDU X6311 Fuse fail"/>
</area>
</areas>~/t/ftemp $
~/t/ftemp $ xslt2 richard.xml richard.xsl
<?xml version="1.0" encoding="UTF-8"?>
<areas>
<area name="LAR 23">
<alarm equipment="1 Alarm" found="group-2"/>
<alarm equipment="3 Alarm" found="group-2"/>
<alarm equipment="MDU X2301 Relay fail" found="group-3" found-group="1"
found-key="2301"/>
<alarm equipment="2 Alarm" found="group-2"/>
<alarm equipment="MDU X2301 Fuse fail" found="group-3" found-group="2"
found-key="2301"/>
</area>
<area name="LAR 41">
<alarm equipment="MDU X4107 Relay fail" found="group-3" found-group="1"
found-key="4107"/>
<alarm equipment="MDU X4107 Fuse fail" found="group-3" found-group="2"
found-key="4107"/>
<alarm equipment="MDU X4108 Relay fail" found="group-3" found-group="1"
found-key="4108"/>
<alarm equipment="MDU X4108 Fuse fail" found="group-3" found-group="2"
found-key="4108"/>
<alarm equipment="Frame 1 PSU 1" found="group-1"/>
<alarm equipment="Frame 1 PSU 2" found="group-1"/>
<alarm equipment="Fan Tray 1" found="group-1"/>
</area>
<area name="LAR 51">
<alarm equipment="1 Alarm"/>
<alarm equipment="3 Alarm"/>
<alarm equipment="Frame 1 PSU 1" found="group-1"/>
<alarm equipment="Frame 1 PSU 2" found="group-1"/>
<alarm equipment="Fan Tray 1" found="group-1"/>
</area>
<area name="LAR 53">
<alarm equipment="1 Alarm" found="group-2"/>
<alarm equipment="2 Alarm" found="group-2"/>
<alarm equipment="Rack 5308 Power Fail Alarm"/>
<alarm equipment="Rack 5309 Power Fail Alarm"/>
<alarm equipment="3 Alarm" found="group-2"/>
</area>
<area name="LAR63">
<alarm equipment="MDU X6311 Relay fail" found="group-3" found-group="1"
found-key="6311"/>
<alarm equipment="MDU X6311 Fuse fail" found="group-3" found-group="2"
found-key="6311"/>
</area>
</areas>~/t/ftemp $
~/t/ftemp $ cat richard.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"><xsl:output indent="yes"/> <xsl:variable name="groupedAlarms"
select="doc('groups.xml')/groups/group"/><xsl:template match="area">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:variable name="thisAlarmArea" select="."/>
<!--find all alarm groups where every group member is in the alarm-->
<xsl:variable name="foundGroups" select="$groupedAlarms
(:there can be no mis-matches:)
[every $groupAlarm in alarm satisfies
some $areaAlarm in $thisAlarmArea/alarm
satisfies matches( $areaAlarm/@equipment,
concat('^',$groupAlarm/@equipment,'$'))]"/>
<!--walk through the area alarms, annotating those that are found in
the found groups (ignoring those groups where not all were found)-->
<xsl:for-each select="alarm">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:variable name="thisAreaAlarm" select="."/>
<!--only bother looking through the found groups, not others-->
<xsl:for-each select="$foundGroups">
<xsl:for-each select="alarm[matches($thisAreaAlarm/@equipment,
concat('^',@equipment,'$'))]">
<!--found the grouped alarm that the area alarm matches-->
<xsl:variable name="thisGroupedAlarm" select="."/>
<xsl:attribute name="found" select="../@id"/>
<xsl:analyze-string select="$thisAreaAlarm/@equipment"
regex="^{$thisGroupedAlarm/@equipment}$">
<xsl:matching-substring>
<xsl:for-each select="regex-group(1)[normalize-space(.)]">
<xsl:attribute name="found-group">
<xsl:number select="$thisGroupedAlarm"/>
</xsl:attribute>
<xsl:attribute name="found-key" select="."/>
</xsl:for-each>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:for-each>
</xsl:for-each>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template><xsl:template match="@*|node()"><!--identity for all other nodes-->
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template></xsl:stylesheet>~/t/ftemp $ ~/t/ftemp $
|

Cart



