Subject: Re: [xsl] two level grouping problem From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Thu, 25 Oct 2007 17:41:39 -0400 |
I am trying to group down to two levels. Here is a sample of the
original xml (blank lines added for clarity):
...
Here is what I am looking for. Notice that the g_codes have been
grouped and the AK objectives have been groups together separated by
a pipe character.
...
My current XSLT:
...
<xsl:key name="gcode_key" match="standard" use="g_code"/>
<xsl:key name="state_by_gcode" match="standard" use="concat(., '+', / standard/state-objective/@state)" />
Apparently my first group key is working. I am not sure what the second one is doing, if anything. Can anyone show me where I am going wrong?
T:\ftemp>type terry.xml <state> <standard><g_code>G4U1S01</g_code> <state-objective state="AL">R.3.6. Blah blah blah</state-objective></standard>
<standard><g_code>G4U1S02</g_code> <state-objective state="AL">R.3.7. Blah blah blah</state-objective></standard> . . . . </state>
T:\ftemp>type terry.xsl <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="gcode_key" match="standard" use="g_code"/> <xsl:key name="state_by_gcode" match="standard" use="concat(g_code, '+', state-objective/@state)" />
<xsl:template match="/"> <xsl:for-each select="/state/standard[generate-id(.)= generate-id(key ('gcode_key' , g_code))]/g_code"> <xsl:sort/>
<xsl:text> </xsl:text> <standard> <g_code><xsl:value-of select="."/></g_code> <xsl:text> </xsl:text>
<xsl:for-each select="key('gcode_key', .) [generate-id() = generate-id(key('state_by_gcode', concat(g_code, '+', state-objective/@state))[1])]"> <xsl:sort select="state-objective/@state"/> <state-objective state="{state-objective/@state}"> <xsl:for-each select="key('state_by_gcode', concat(g_code, '+', state-objective/@state))"> <xsl:if test="position()>1"> | </xsl:if> <xsl:value-of select="state-objective"/> </xsl:for-each> </state-objective> <xsl:text> </xsl:text> </xsl:for-each> </standard> </xsl:for-each> </xsl:template>
T:\ftemp>type terry.out <?xml version="1.0" encoding="UTF-8"?>
<standard> <g_code>G4U1S01</g_code>
<standard> <g_code>G4U1S02</g_code>
</standard> T:\ftemp>rem Done!
-- Comprehensive in-depth XSLT2/XSL-FO1.1 classes: Austin TX,Jan-2008 World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Jul'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] two level grouping problem, Terry Ofner | Thread | RE: [xsl] Re: XSL to ODF/OOXML, W Charlton |
RE: [xsl] Re: XSL to ODF/OOXML, Scott Trenda | Date | RE: [xsl] Re: XSL to ODF/OOXML, Michael Kay |
Month |