Re: [xsl] using xsl:for-each-group, grouping by child nodes?

Subject: Re: [xsl] using xsl:for-each-group, grouping by child nodes?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 05 Oct 2008 10:46:35 -0400
At 2008-10-06 01:06 +1100, Eric Scheid wrote:
OK, this almost works for me - the xml I posted to the list was a bit
simplified and I must be screwing up the last bit of retrofitting. The
actual full XML is this:

<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult";>
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="06-20-2006" NAME="FileMaker Pro" VERSION="8.5v1"/>
...

So I thought the code needed to be tweaked like this:

...
<xsl:template match="/fmp:FMPXMLESULT">
   <!--group first by team; using a key of two parts with an unlikely
       character in between to avoid any ambiguous concatenations-->
   <xsl:variable name="players" select="/fmp:FMPXMLESULT/*/fmp:ROW"/>
...

(btw, is there any short-hand way to avoid having to specify the fmp9
prefix everywhere like this?)

Not in XSLT 1.0, but xpath-default-namespace= can be used if you were using XSLT 2.0. As Mike said that XSLT 2.0 feature is a handy default when *everything* is in a single namespace, as in your case, but for my work where there is more than one namespace I find it a good practice to keep up with the prefixes in my stylesheet.

but I9m getting the wrong output:

0joe2pitchernymetsmark11outfieldernymetsjohn23pitchernymetspete27outfieldern
ycubsroy13outfieldernycubscarl32infieldernycubs

Absent the white-space indentation of your source file, I note that string is a concatenation of all of the text nodes. That's an important clue: it seems that all of your XML is going through the built-in template rules. That led me to look at your template matches and it took me surprisingly long to find the issue.

My eyes are tired - I probably did something stupid.

Don't kick yourself too hard but it is a simple typo (something that schema-aware XSLT 2.0 helps to address) ... you've spelled "FMPXMLRESULT" as "FMPXMLESULT" in your XSLT. Changing both of those typos on my side produces the anticipated output. I do the same mistake often in my UBL stylesheets where the element names are so very long.

I see you run training courses .. are you thinking of coming to Sydney
anytime soon?

It all depends on how well-subscribed the Wellington class is ... if I don't get enough registrants I'll propose running the same two classes (XSLT and XSL-FO) in Sydney on the same January/February 2009 dates. Don't think there is enough time (or registrants!) to do both! Thanks for asking ... even if you can't attend, any help to spread the word by anyone on the list would be very much appreciated. The DVD we sell is the same as the 5-day XSLT class, so the YouTube segments linked in my trailer below are a preview of both the instructor-led and self-paced deliveries. The benefit in the instructor-led class is that students can bring their own data to class for exercises and I'm available for any and all questions.

I hope this helps, Eric.

. . . . . . . . . . Ken


-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread