RE: [xsl] Testing if all child nodes match (based on the value of certain elements)

Subject: RE: [xsl] Testing if all child nodes match (based on the value of certain elements)
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 23 Apr 2007 22:11:54 +0100
>      <xsl:when test="not( group/person/age != group/person/age ) and
>                      not( group/person/sex != group/person/sex )">

That's likely to be quite expensive if it's a large dataset: a better
solution with XSLT 2.0 is

count(distinct-values(group/person/age))==1 and
count(distinct-values(group/person/sex))==1

Perhaps even better, given that you're dealing with siblings, is

not(group/person[age=preceding-sibling::person[1]/age and
sex=preceding-sibling::person[1]/sex])

which also works in 1.0.

But the performance of the different constructs depends on the optimizer, on
the size of the dataset, and also on the probability of the condition being
true.

Michael Kay
http://www.saxonica.com/

Current Thread