Subject: Re: [xsl] conditional copying of nodes? From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Wed, 22 Aug 2001 10:04:42 +0100 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] conditional copying of nodes?, Hewko, Doug | Thread | RE: [xsl] conditional copying of no, Hewko, Doug |
Re: [xsl] separating elements/attri, Jeni Tennison | Date | Re: [xsl] conditional copying of no, Joerg Pietschmann |
Month |