Subject: Re: [xsl] group-by an optional attribute From: "Mark" <mark@xxxxxxxxxxxx> Date: Tue, 22 Nov 2011 10:43:54 -0700 |
Thanks, Mark
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">
what you wrote should be legal but whether it "works" depends on how you want things to group.
usually does what I want in these situations, but whether it does what you want, I can't guess:-)
if you select nothing then things go in no group, but by using string() you never select nothing and things without the attribute end up in the group keyed on the string "". this assumes that there is at most one Stamp child.
-- google plus: https:/profiles.google.com/d.p.carlisle
________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] group-by an optional attr, David Carlisle | Thread | [xsl] Wrap an entire element if it , Rick Quatro |
Re: [xsl] group-by an optional attr, David Carlisle | Date | Re: [xsl] group-by an optional attr, G. Ken Holman |
Month |