This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: cross document id idref pair checks



Jeni Tennison 
> I think (?) that DaveP meant duplicated values for @id attributes
> across a document rather than duplicate @id attributes on a particular
> element.
> 
> If there is an element that has the same @id attribute as the current
> element, then:
> 
> You can get elements that have repeated ids with:
> 
>   //*[@id = (preceding::*/@id | following::*/@id)]

but noted comment on efficiency.

> If, for an element, the 'ids' key returns more than one node, then
> it's a repeated id, so you can test whether there are any repeats
> with:
> 
>   //*[key('ids', @id)[2]]

I like the look of that.



> If you want to get a list (without repeats) of the repeated IDs using
> the key() method, then you can use the usual:
> 
>   //*[key('ids', @id)[2] and
>       count(.|key('ids', @id)[1]) = 1]

I'd dispute the use of the word 'usual' here Jeni :-)



> 
> [or actually, by extension to the above aside:
> 
>   //*[key('ids', @id)[2] and
>       not((.|key('ids', @id)[1])[2])]
> 
>  making identity-testing of nodes even more obscure! :)]

I won't disagree with the latter comment!!


> 
> Testing this across documents is harder 

But not required, the test is that no two elements share the same id value
in the document under test (which is the source document)

Thanks Jeni. 

I'll run some timing on those and compare with DC's 'count() method.

Regards DaveP

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]