.... Having said al..." />

How to select the first node for each value of a given attribute using XSLT?

I would suggest to replace your template with: xsl:template match="groupgenerate-id(.) = generate-id(key('groupsByName',@name)1)"> .... Having said all this we get: group@namegenerate-id(.) = generate-id(key('groupsByName', @name)1).

I would suggest to replace your template with: .... Or just change your xpath expression to //groupgenerate-id(.) = generate-id(key('groupsByName',@name)1). Count(.|some-node-set) is usually used to check whether some node belongs to the set or not. Here you need to compare current node with the first some unique node for each group.

Also it might be useful to improve an Xpath expression and match only those group elements which have @name attributes. Having said all this we get: //group@namegenerate-id(.) = generate-id(key('groupsByName', @name)1).

Changing the expression to //groupgenerate-id(.) = generate-id(key('groupsByName',@name)1) worked nicely, thank you. I'm doing some other things within the template, so I didn't want to change the template itself. Thank you also for the additional explanation.

– Jon Bright Mar 10 at 17:48 Nokolaenkov: This explanation is wrong. Both forms of identity check are used even in classic Jeni Tennison's page. Although because the symmetrical inclusion is simplificated, one has to be sure that both expression (. and key($name,$value)1) are singleton and not empty node sets.

Symmetrical inclusion from the Set Theory is the pure XPath solution to the identity test, because generate-id() is an XSLT only function. – user357812 Mar 10 at 18:22 @Alejandro, why is it wrong? Using generated ids to check whether two nodes are equal or not is more natural than than computing power of the set to identify this.

Even that count(.|set-of-one) = 1 is a well-known idiom, it relies on subtle semantics of the | operator and 1 is a magic number. If using sets that would be more correct to write count(.|set-of-one) = count(set-of-one). That's matter of taste but that Jenny page says nothing about that.

However thanks for raising the question. – Alex Nikolaenkov Mar 10 at 18:37 It's wrong because it doesn't explain what I'm explaining, and because a simple replacing of! = by = would be enough for the question purpose.

The symmetrical inclusion isn't a "subtle semantic": A = B A c B ^ B c A – user357812 Mar 10 at 18:54 @Alejandro, sorry cannot agree with your definition of correctness. If you prefer the details then | in the xpath it means (spec mode on): "The | operator computes the union of its operands, which must be node-sets. " (/spec mode off) In some other languages the very same operator means bitwise OR and therefore definiton of this operator in the XPath is specific (= subtle semantics).

Thinking in terms of set theory is of course preferred when dealing with the xpath's | but I prefer straightforward generate-id way over artifical count. YMMV. Maybe I should have noted another opportunity.

– Alex Nikolaenkov Mar 10 at 19:24.

Just replace: //groupcount(.|key('groupsByName',@name)1)! =1 with: //groupcount(.|key('groupsByName',@name)1)=1 Here is a complete solution: when this transformation is applied on the provided XML document (fixed to be well-formed): ...stuff... ...different stuff... ...same stuff as first foo group... the wanted, correct result is produced: foo bar.

1. BTW why do you prefer count way over generate-ids? – Alex Nikolaenkov Mar 10 at 19:25 +1 Correct answer closer to question.

– user357812 Mar 10 at 20:05 @Alex-Nikolaenkov: I do not "prefer" this way, but the OP was asking what was the problem with his solution -- the real problem was that he was using the! = operator instead of the = operator. Strictly speaking, I answered the question and you didn't.

– Dimitre Novatchev Mar 10 at 20:55.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions