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

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

Subject: RE: [xsl] Pattern Matching in XSl - find groups defined in one Xml in another Xml.
From: "Kerry, Richard" <richard.kerry@xxxxxxxx>
Date: Wed, 29 Aug 2012 16:16:27 +0000

Regarding Ken's solutions from last Wednesday (repeated below), why is it :

<xsl:analyze-string select="$thisAlarm/@equipment"
<xsl:for-each select="regex-group(1)[normalize-space(.)]">
<xsl:attribute name="found-key" select="."/>

rather than

<xsl:analyze-string select="$thisAlarm/@equipment"
<xsl:attribute name="found-key" select="regex-group(1)"/>


What does the [normalize-space(.)] predicate do for us ?


By the way, this does seem to give the right results.
I'm only now getting back to looking at it and working out how it works,
having had a few days off over the (UK) Bank Holiday weekend.

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

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.

From: G. Ken Holman [g.ken.holman@xxxxxxxxx] on behalf of G. Ken Holman
Sent: 22 August 2012 18:29

~/t/ftemp $ cat richard.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

<xsl:output indent="yes"/>

<xsl:variable name="groupedAlarms"

<xsl:template match="area">
     <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,
     <!--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: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,
             <!--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"
                 <xsl:for-each select="regex-group(1)[normalize-space(.)]">
                   <xsl:attribute name="found-group">
                     <xsl:number select="$thisGroupedAlarm"/>
                   <xsl:attribute name="found-key" select="."/>

<xsl:template match="@*|node()"><!--identity for all other nodes-->
     <xsl:apply-templates select="@*|node()"/>

</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