[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: conditional copying of nodes?

Subject: Re: conditional copying of nodes?
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 22 Aug 2001 10:04:42 +0100
Re:  conditional copying of nodes?
Hi Doug,

> How can I do conditional copying of nodes? For example, I have the
> following XML snippet, with an individual being in one or many
> groups. I am doing a Muenchian method sort, which works. (Thanks
> Jeni!) The problem is that I am unable to put someone more than one
> group unless I physically duplicate their record. In the example
> below, I would copy my name, e-mail and phone twice; once using the
> <group> of "Core Group" and once using "Steering Committee".

The Muenchian method only works if each thing that you index (e.g.
member) is only indexed by one value. The cause lies in the way that
you get the unique values for the groups, when you do:

  member[count(.|key('members', group)[1]) = 1]

The key() returns all the members who are in the same group as this
one. If the member is in several groups, then you'll get all the
members in any of the groups. All the members will be arranged in
document order. The [1] predicate then picks the first one from all
these different groups. The member might be first in one of the
groups, but not the first in another group; if so (and if the other
group's first member is before this one) then the member won't be
selected.

So that's why - you need to know how to deal with it. Well, change the
key so that it indexes the elements that have unique values; in this
case the group elements by their value:

<xsl:key name="groups" match="group" use="." />

Now you can get a list of the groups with the path:

  member/group[count(.|key('groups', .)[1]) = 1]

You'll have to change the code a bit because the group element is now
the current node (rather than the member element). For example, to get
all the members of a group, you need:

  key('groups', $group)/parent::member

I hope that's enough to enable you to get it working. Come back for
more details if you need to.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.