xsl:for-each-group error...

H

hzgt9b

I am a bit of a newbie to XSLT and am feeling my way around. Here is a
sample I found on the internet that I am trying to replicate on my
machine but am having problems. Specifically, the "<xsl:for-each-
group" element gets an error: "Keyword xsl:template may not contain
xsl:for-each-group ". I can find documentation for this element, so
I'm a bit lost as to the source of the problem. Anyone have any ideas.
See my XML ans XSL files below:

Thanks in advance,
celoftis

XML: (saved as test.xml)
----------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<cities>
<city name="Williamsburg" state="Virginia" pop="11998" />
<city name="New York City" state="New York" pop="80000" />
<city name="Washington" state="DC" pop="553523" />
<city name="Richmond" state="Virginia" pop="300000" />
</cities>


XSL: (saved as test.xsl)
----------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template match="/">
<table>
<xsl:for-each-group select="cities/city" group-by="@state"> <!--I can
see error on this line (I can't copy the tooltip contant, but it's
something like,'for-each-group' is invalid child element for template,
etc.....) -->
<tr>
<td><xsl:value-of select="@state" /></td>
<td>
<xsl:value-of select="current-group()/@name" separator=", " />
</td>
<td><xsl:value-of select="sum(current-group()/@pop)" /></td>
</tr>
</xsl:for-each-group>
</table>
</xsl:template>
</xsl:stylesheet>
 
M

Martin Honnen

hzgt9b said:
I am a bit of a newbie to XSLT and am feeling my way around. Here is a
sample I found on the internet that I am trying to replicate on my
machine but am having problems. Specifically, the "<xsl:for-each-
group" element gets an error: "Keyword xsl:template may not contain
xsl:for-each-group ". I can find documentation for this element, so
I'm a bit lost as to the source of the problem. Anyone have any ideas.
See my XML ans XSL files below:
<?xml-stylesheet type="text/xsl" href="test.xsl"?>

That suggests you are trying to let a browser apply the XSLT
transformation. However your stylesheet
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template match="/">
<table>
<xsl:for-each-group select="cities/city" group-by="@state"> <!--I can

is an XSLT 2.0 stylesheet and xsl:for-each-group is an XSLT 2.0
instruction while XSLT processors in browsers like IE, Mozilla, Opera 9,
Safari 2 only support XSLT 1.0.

If you need an XSLT 2.0 processor try Saxon 8.9 from
<URL:http://saxon.soureforge.net/>

If you want to use a browser then you will have to stick with XSLT 1.0.
 
H

hzgt9b

Thanks for the quick reponse Martin. I was able to get that working!

Doing the transform in the browser was what I was shooting for (and is
easier to distribute) - can anyone suggest any XSLT1.0 compliant
elements that do the equivalent of the <xsl:for-each-group>? A little
more background - I'm trying to get a list (group) elements like the
state example above, then for each item in that list (group) transform
all the matching elements (XPATH) in the XML file into a report, where
each item may have a different xslt template associated with it...

Any inout would be appreciated.
 
P

PC Paul

hzgt9b said:
I'll have a look - thanks again for your help and timely responses.

But you will soon realise *why* a new keyword for doing this was
introduced in XSL 2.0...
 
J

Joe Kesselman

PC said:
But you will soon realise *why* a new keyword for doing this was
introduced in XSL 2.0...

And someday XSLT 2.0 will find its way into browsers and so on. But for
now, if you're concerned about running on software (including browsers)
already installed on the customer's machine, 1.0 is the way to bet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top