[xsl] group-by an optional attribute

Subject: [xsl] group-by an optional attribute
From: "Mark" <mark@xxxxxxxxxxxx>
Date: Tue, 22 Nov 2011 10:12:41 -0700
Hi,
Consider:
<xsl:for-each-group select="current-group()" group-by="Stamp/@line"

This fails because @line is an optional attribute and does not always appear in the XML. The only cure I can think of is to run a pre-processing stylesheet that, should the @line attribute be absent from a <Stamp> element, adds an @line="0" to each <Stamp> element. This is not a problem, but I wondered if there were another more elegant means making the group-by work?

I tried to formulate an alternative, thinking this would group-by the true value of @line were it present, or by zero in its absence, but it fails:
<xsl:for-each-group select="current-group()" group-by="if(Stamp/@line) then Stamp/@line else 0">


Thanks for any help,
Mark

Current Thread