RE: [xsl] Filter nodelist

Subject: RE: [xsl] Filter nodelist
From: Jarno.Elovirta@xxxxxxxxx
Date: Thu, 7 Nov 2002 13:38:49 +0200
Hi,

> I have an XML document that contains a few 'product' elements 
> with 'id'
> attributes. Because I have to operate on these products a few times I
> build a variable that just takes all products with the expression
> 'descendant::product'. Sometimes I have to iterate over all products.
> But that is not all I do with the list. My problem: I have to get the
> count of all products from this node-list that have the same id like a
> certain product in the list  and that's position in the node-list is
> lower. Example:
> 
> [product id="A",
>  product id="B",
>  product id="C",
>  product id="B",
>  product id="B",  <-
>  product id="D",
>  product id="E"]
> 
> So if I have the product at position 5 the result of the 
> count should be
> 2, because of the products at position 2 and 4 with the same id.

E.g.

  count($theCurrentProduct/preceding::product[@id = $theCurrentProduct/@id])

but it's very inefficient.

Cheer,

Jarno

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


Current Thread