|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: using xsl:for-each-group, grouping by child nodes?
At 2008-10-05 01:06 +1000, Eric Scheid wrote:
Sadly, it seems the tool I'm using (Filemaker Pro) doesn't like it, throwing an error of "Unknown XSL element: for-each-group". I'm guessing it doesn't support XSLT 2.0 functions yet, which is a bummer. Then use XSLT 1.0 to solve the problem ... no reason to give up. I hope the below helps. . . . . . . . Ken
t:\ftemp>type eric.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"><xsl:output method="text"/> <xsl:template match="/">
<!--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="/*/ROW"/>
<xsl:for-each select="$players">
<xsl:if test="generate-id(.)=
generate-id($players[concat(COL[4]/DATA,'
',COL[5]/DATA)=
concat(current()/COL[4]/DATA,'
',current()/COL[5]/DATA)][1])">
<!--found the first player for a given team-->
<xsl:if test="generate-id(.)!=generate-id($players[1])">
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:text>
 Team: </xsl:text>
<xsl:value-of select="concat(COL[5]/DATA,', ',COL[4]/DATA)"/>
<xsl:variable name="team"
select="$players[concat(COL[4]/DATA,'
',COL[5]/DATA)=
concat(current()/COL[4]/DATA,'
',current()/COL[5]/DATA)]"/>
<!--now group by position; reflecting plural where applicable-->
<xsl:for-each select="$team">
<xsl:if test="generate-id(.)=
generate-id($team[COL[3]/DATA=current()/COL[3]/DATA][1])">
<xsl:text>
 </xsl:text>
<xsl:value-of select="COL[3]/DATA"/>
<xsl:variable name="position"
select="$team[COL[3]/DATA=current()/COL[3]/DATA]"/>
<xsl:if test="count($position)>1">s</xsl:if>:<xsl:text/>
<!--show all in the position-->
<xsl:for-each select="$position">
<xsl:text>
 </xsl:text>
<xsl:value-of select="concat( COL[1]/DATA,', ',COL[2]/DATA )"/>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:template></xsl:stylesheet> t:\ftemp>call xslt eric.xml eric.xsl eric.out t:\ftemp>type eric.out Team: mets, ny
pitcher:
joe, 2
outfielders:
mark, 11
mike, 7 Team: cubs, ny
outfielder:
jane, 13
t:\ftemp>rem Done!-- 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








