[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, 22 Aug 2012 13:30:31 +0000

Thanks for your comments.
You've (inadvertently ?) answered one of the questions I had in my mind, which
was :
Has Ken just missed a detail of the requirements which can easily be altered
to suit, or is there something major that needs changing ?
You've clearly suggested that the former is the case - I shall have to spend
some more time understanding these implementations.  And yours.

In particular I don't yet understand keys.  I've seen the term used over the
years and failed to understand what it really meant.  Until now I 've never
really needed to.

And I see I have another reply from Ken today .....


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: Wendell Piez [wapiez@xxxxxxxxxxxxxxxx]
Sent: 21 August 2012 18:06
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Pattern Matching in XSl - find groups defined in one  Xml
in another Xml.

Dear Richard,

Ken has actually demonstrated everything you need to know in the problem
you pose. Indeed, since the difference between his solution 1 and
solution 2 is effectively the matching criterion -- what qualifies an
entry as "found" -- then comparing the two should show you what you need
to generalize to any matching criteria you may have (comparing two or
more values, etc.).

It's true that in giving you complete solutions, he hasn't separated the
solution to the problem as posed from the incidentals that go with
making it work. But this makes good homework. (By not breaking it down
and explaining it he's actually expressing his confidence in you, I'd
say.) So I suggest taking the next step by picking one of his solutions
and tinkering with it. (Undoubtedly you are already doing this.) Do feel
free while you are doing so to come back to the list with more questions.

If it were my problem I might encapsulate the test for a match into a
stylesheet function, both for clarity and maintenance. A first step
could be to do this with Ken's solution 1, something like

<xsl:function name="x:my-group" as="element(group)*">
   <!-- returns any 'group' elements in groups.xml with child
        nodes matching $me/@equipment by the 'grouped' key -->
   <xsl:param name="me" as="element(alarm)"/>

(I did make a slight change from Ken's logic: this fetches the 'group'
element not the 'alarm' element inside it.)


<xsl:template match="alarm">
     <xsl:apply-templates select="@*"/>
     <xsl:for-each select="x:my-group(.)">
       <xsl:attribute name="found" select="@id"/>

Once the logic is embedded in the function you can extend or refine it
as much as you like. Nor do you have to use a key, as Ken did (and then
didn't in his second solution): what the function does is return the
elements from your lookup document that correspond with the 'alarm'
element being matched, and any way it does that is fine.


Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
   Mulberry Technologies: A Consultancy Specializing in SGML and XML

Current Thread