[XSL-LIST Mailing List Archive Home]
Re: [xsl] Cannot use a parameter value in the group-starting-with attribute?
Subject: Re: [xsl] Cannot use a parameter value in the group-starting-with attribute?|
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 14 May 2010 21:07:27 +0100
On 14/05/2010 20:49, Peter Desjardins wrote:
Hi. I'm writing a 2.0 stylesheet and my processor is Saxon HE 184.108.40.206.
Also, I'm just starting out with XSLT.
I am trying to create a template with parameters that will use the
for-each-group element. I find that I cannot use a parameter value in
the group-starting-with attribute.
There are two problems there, one is that patterns use a restricted
syntax compared to xpath, but more importantly parameters and variables
in xpath hold _values_ (as they would in c or fortran) not fragments of
syntax 9as they would in a shell scripting language)
so when you go <xsl:with-param name="starting-element" select = "h1" />
the parameter does not hold the fragment of a pattern "h1" it holds the
result of ebaluating teh expression h1 at that point, which is a
possibly empty sequence of h1 nodes.
the this works
<xsl:for-each select = "$starting-element">
but it is not (at that point) selecting h1 elements it is simply
iterating over the list of elements that has already been selected and
stored in the $starting-element variable.
but this could not work even if it were not a syntax error
<xsl:for-each-group select = "*" group-starting-with = "$starting-element">
the grouping attributes need to take patterns or expressions used to
filter the nodes selected, not take a sequence of nodes.
so do not pass in a sequence of nodes, pass in a string:
<xsl:with-param name="starting-element" select = "'h1'" />
(note the extra quotes(
then you can use that string in a pattern
<xsl:for-each-group select = "*"
group-starting-with = "*[name()=$starting-element]">