Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT: Check if a value exists in a list

So, I have a variable containing a nodeset with several Size nodes

<xsl:variable name="sizes" select="$filter/Size" />

I then, need to do a sum on another nodeset, where the Size/@ID exists in this $sizes variable

<xsl:value-of select="sum(Sizes/Size[ **where @ID in $sizes/@ID** ]/@Value)"/>

But I'm struggling on how I write this XPath...in xslt 1.0

like image 511
CaffGeek Avatar asked Nov 14 '11 21:11

CaffGeek


1 Answers

<xsl:value-of select="sum(Sizes/Size[@ID = $sizes/@ID]/@Value)"/>

if I understand your spec correctly.

This works because of "existential quantification": A = B means "some member of node set A is equal to some member of node set B". (In your case, A has at most only one member anyway.)

like image 80
LarsH Avatar answered Sep 19 '22 17:09

LarsH