RE: [xsl] How to do an 'existence' test in XSL?
Subject: RE: [xsl] How to do an 'existence' test in XSL?|
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 22 Dec 2004 14:25:18 -0500
It may not be strictly a full-blown grouping problem, but the problem of
uniquely identifying a single node to stand for a set of nodes is part of
the general problem of grouping. So solutions (and there are several) can
be found in the common solutions for grouping.
Think of it like this: group the nodes, and for each group report a single
value. You don't need to know ahead of time what those values might be.
At 01:38 PM 12/22/2004, you wrote:
To me, your solution is not as simple as it could be.
Mukul's solution is to test on the preceding-sibling axis to see whether
any nodes preceding have the same value, and can therefore be presumed to
be accounted for.
It may not be the most elegant approach imaginable (as Mike said you have
to go to XSLT 2.0 for that), and it is not very performant over large
datasets, but it works ... and it's not that complicated either.
Other approaches to identifying what I call a "flag-bearer" node include:
B. setting up a key and then seeing whether each node is the first (or
last, if you like) returned by the key with its key value
C. doing brute force retrieval of the nodes like this one, and seeing if
this one is the first
B is often the preferred approach, as being both not overly complex, and
performant even over fairly large data sets. Whether it's "simple" depends
on whether you consider keys simple. (I think they're pretty simple, but
then I've got an XSLT 1.0 processor installed in my brain.)
All these will work over node sets whose relevant values ("alertbox",
"tooltip", "help") are not known ahead of time.
As Mike indicated, the techniques are documented in Jeni's pages on
grouping at www.jenitennison.com/grouping. And as he also indicated, the
particular feature of the language wanted -- a gap filled in XSLT 1.0 by
the grouping techniques just described above -- is actually provided in
XSLT 2.0's "for-each-group" construct.
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