|
Subject: RE: [xsl] Pattern Matching in XSl - find groups defined in one Xml in another Xml. From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 21 Aug 2012 15:01:51 -0400 |
Ok, Thanks Ken, I've got both of these solutions working as given, with the results as stated.
However ....
They don't quite implement the spec as given.
> The pattern must be found in its entirety (ie LAR 51 doesn't find "group-2" as "2 Alarm" is not present).
Both the solutions provided are indicating group-2 is present for LAR 51 but this is not so as "2 Alarm" is not actually present there.
<group id="group-2"> <alarm equipment="1 Alarm"/> <alarm equipment="2 Alarm"/> <alarm equipment="3 Alarm"/> </group>
<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>
The pattern given must match in its entirety for a match to be declared.
(There may be a further subsidiary issue if I find I need to be able to match "subset" groups, ie where one defined match group is a subset of another but the smaller group may only be matched if the larger one doesn't - ignore this for now; I'll need to work out whether it's necessary once I've got something nearer to the full data.)
> I can help if you don't mind using the following notation using grouping parentheses:
That's no problem - I can adapt the group spec format as I'll be writing that based on a brief visual analysis of the main data.
As I haven't yet had the final data to work on and haven't yet determined exactly how I want the results organized I am interested at the moment in working out the principles of the task and I'll sort out the details later.
<xsl:variable name="groupedAlarms"
select="doc('groups.xml')/groups/group/alarm"/><xsl:template match="alarm">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:variable name="thisAlarm" select="."/>
<xsl:for-each select="$groupedAlarms
[matches($thisAlarm/@equipment,
concat('^',@equipment,'$'))]">
<xsl:attribute name="found" select="../@id"/>
<xsl:variable name="thisGroupedAlarm" select="."/>
<xsl:analyze-string select="$thisAlarm/@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: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 $
-- Public XSLT, XSL-FO, UBL and code list classes in Europe -- Oct 2012 Contact us for world-wide XML consulting and instructor-led training Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Pattern Matching in XSl -, Wendell Piez | Thread | RE: [xsl] Pattern Matching in XSl -, Kerry, Richard |
| Re: [xsl] XPath shorthand, Dimitre Novatchev | Date | Re: [xsl] XPath shorthand, Ihe Onwuka |
| Month |