[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Pattern Matching in XSl - find groups defined in one Xml in another Xml.


Subject: [xsl] Pattern Matching in XSl - find groups defined in one Xml in another Xml.
From: "Kerry, Richard" <richard.kerry@xxxxxxxx>
Date: Tue, 21 Aug 2012 13:38:06 +0000

How can I use XSL to detect patterns in one XML file defined in another ?

I have two files :
1.  The data I'm given.
2.  The file I've created with the patterns I want to find.

An abridged example of the given data might be :
<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>

If the pattern data is:
<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>
</groups>

The result would be :
<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"/>
<alarm equipment="2 Alarm" found="group-2" />
<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" 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"/>
<alarm equipment="MDU X6311 Fuse fail"/>
</area>
</areas>

You can see that a "found" attribute has been added wherever a pattern from
the pattern file has been found.  The pattern must be found in its entirety
(ie LAR 51 doesn't find "group-2" as "2 Alarm" is not present).  The order of
items is unimportant (ie LAR 23 does find group-2 despite not being in the
order it's defined in).

- Supplementary question.
Can this be extended to find patterns defined using regular expressions ?
eg add to the above pattern file :
<group id="group-3">
<alarm equipment="MDU X[0-9]{4} Relay fail"/>
<alarm equipment="MDU X[0-9]{4} Fuse fail"/>
</group>

The result would be changed to add the following :

<area name="LAR 23">
<alarm equipment="MDU X2301 Relay fail" found="group-3" found-group="1"
found-key="2301" />
<alarm equipment="MDU X2301 Fuse fail" found="group-3" found-group="1"
found-key="2301" />

<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="1"
found-key="4107" />
<alarm equipment="MDU X4108 Relay fail" found="group-3" found-group="2"
found-key="4108" />
<alarm equipment="MDU X4108 Fuse fail" found="group-3" found-group="2"
found-key="4108" />

<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="1"
found-key="6311" />

Found-group distinguishes the instances of the group found, with found-key
giving the specific differing matched text.

Can someone advise how to go about this sort of task ?


Regards,
Richard.




Richard Kerry
BNCS Engineer
T: +44 (0)20 82259063
M: +44 (0)7812 325518
Room EBX 301, BBC Television Centre, Wood Lane, London, W12 7RJ
richard.kerry@xxxxxxxx
uk.atos.net

This e-mail and the documents attached are confidential and intended solely
for the addressee; it may also be privileged. If you receive this e-mail in
error, please notify the sender immediately and destroy it. As its integrity
cannot be secured on the Internet, the Atos group liability cannot be
triggered for the message content. Although the sender endeavours to maintain
a computer virus-free network, the sender does not warrant that this
transmission is virus-free and will not be liable for any damages resulting
from any virus transmitted.


Current Thread
Keywords