[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

two level grouping problem

Subject: two level grouping problem
From: Terry Ofner <tofner@xxxxxxxxxxx>
Date: Thu, 25 Oct 2007 16:19:35 -0400
 two level grouping problem
I am trying to group down to two levels. Here is a sample of the original xml (blank lines added for clarity):

<state>
<standard><g_code>G4U1S01</g_code>
<state-objective state="AL">R.3.6. Blah blah blah</state-objective></ standard>


<standard><g_code>G4U1S01</g_code>
<state-objective state="AK">[4] 2.1.4. Blah blah blah</state- objective></standard>


<standard><g_code>G4U1S01</g_code>
<state-objective state="AK">[4] 2.1.2. Blah blah blah</state- objective></standard>


<standard><g_code>G4U1S01</g_code>
<state-objective state="AK">[4] 2.1.1. 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>


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.

<standard>
<g_code>G4U1S01</g_code>
<state-objective state="AL">R.3.6. Blah blah blah </state-objective>
<state-objective state="AK">[4] 2.1.4. Blah blah blah | [4] 2.1.2. Blah blah blah | [4] 2.1.1. Blah blah blah</state-objective>
</standard>


My current XSLT:

<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(., '+', / standard/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>&#10;</xsl:text><standard><g_code><xsl:value-of select="."/ ></g_code><xsl:text>&#10;</xsl:text>

<xsl:for-each select="key('gcode_key', .)
[generate-id() =
generate-id(key('state_by_gcode',
concat(., '+', @state))[1])]">
<xsl:sort select="@state"/>
<xsl:copy-of select="state-objective" /><xsl:text>&#10;</ xsl:text>
</xsl:for-each>
</standard>
</xsl:for-each>
</xsl:template>


</xsl:stylesheet>

It produces the following output:

<standard><g_code>G4U1S01</g_code>
<state-objective state="AL">R.3.6. Blah blah blah</state-objective>
<state-objective state="AK">[4] 2.1.4.Blah blah blah</state-objective>
<state-objective state="AK">[4] 2.1.2. Blah blah blah</state-objective>
<state-objective state="AK">[4] 2.1.1. Blah blah blah</state-objective>
<state-objective state="AZ">R04-S1C4-02. Blah blah blah</state- objective>
. . .
</standard>


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?

Thanks in advance.

Terry Ofner

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.