xsl-list
[Top] [All Lists]

[xsl] grouping problem

2008-04-28 11:15:34
It seems that grouping always gives me trouble. Thanks in advance for any help you can give me.

Here is a snippet of my input xml:

<Root>
<State_Standard state="CA" g_code="G6U5S33">
<state>California Content Standards</state>
<SS>3.6 Narrative Analysis of Grade-Level-Appropriate Text: Identify and analyze features of themes conveyed through characters, actions, and images.</SS>
</State_Standard>

<State_Standard state="CA" g_code="G6U5S37">
<state>California Content Standards</state>
<SS>3.5 Narrative Analysis of Grade-Level-Appropriate Text: Identify the speaker and recognize the difference between first- and third- person narration (e.g., autobiography compared with biography).</SS>
</State_Standard>

<State_Standard state="CA" g_code="G6U6S52">
<state>California Content Standards</state>
<SS>3.4 Narrative Analysis of Grade-Level-Appropriate Text: Define how tone or meaning is conveyed in poetry through word choice, figurative language, sentence structure, line length, punctuation, rhythm, repetition, and rhyme.</SS>
</State_Standard>

<State_Standard state="CA" g_code="G6U5S33">
<state>California Content Standards</state>
<SS>3.2 Narrative Analysis of Grade-Level-Appropriate Text: Analyze the effect of the qualities of the character (e.g., courage or cowardice, ambition or laziness) on the plot and the resolution of the conflict.</SS>
</State_Standard>

<State_Standard state="DE" g_code="G6U4S27">
<state>Delaware Content Standards</state>
<SS>4.2a.4  Test and revise predictions as they read further</SS>
</State_Standard>

<State_Standard state="DE" g_code="G6U4S27">
<state>Delaware Content Standards</state>
<SS>4.2a.3  Make reasonable predictions as they read</SS>
</State_Standard>

<State_Standard state="DE" g_code="G6U4S26">
<state>Delaware Content Standards</state>
<SS>4.2a.1 Make strongly implied inferences about content and concrete ideas in a text and identify appropriate text support</SS>
</State_Standard>

</Root>

I am creating multiple state files using <xsl:result-document> and <xsl:for-each-group> grouping by @state. Then I am attempting to group on the @g_code so as to group <SS> elements whose parents have the same @g_code as in this example snippet based on g_code="G6U5S33" (text removed for display purposes:

<state>California Content Standards</state> G6U5S33 <SS>3.6 Narrative....</SS><SS>3.2 Narrative Analysis of....</SS>

Here is my current xslt (2.0)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">
    <xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
        <xsl:for-each-group select="/Root/State_Standard"
                            group-by="@state">
            <xsl:sort select="current-grouping-key()"/>
<xsl:variable name="stateName" select="current-group() [1]/@state"/>
            <xsl:result-document href="state_out/{$stateName}.txt">

                <xsl:for-each-group select="current-group()"
                                    group-by="@g_code">
                  <xsl:for-each select="current-group()/SS">
<xsl:copy-of select="preceding-sibling::state"/ ><xsl:text>&#09;</xsl:text> <xsl:value-of select="current-grouping-key()"/ ><xsl:text>&#09;</xsl:text> <SS><xsl:value-of select="current-group/SS"/></ SS><xsl:text>&#10;</xsl:text>
                  </xsl:for-each>
                </xsl:for-each-group>

            </xsl:result-document>
        </xsl:for-each-group>
    </xsl:template>
</xsl:stylesheet>


Here is a snippet of the output CA.txt file which shows that the group-by="g_code" does not seem to work as I hoped it would:

<state>California Content Standards</state> G6U5S33 <SS>3.6 Narrative Analysis of Grade-Level-Appropriate Text: Identify and analyze features of themes conveyed through characters, actions, and images.</ SS> <state>California Content Standards</state> G6U5S33 <SS>3.2 Narrative Analysis of Grade-Level-Appropriate Text: Analyze the effect of the qualities of the character (e.g., courage or cowardice, ambition or laziness) on the plot and the resolution of the conflict.</SS>

Again, thanks in advance:

Terry

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] grouping problem, Terry Ofner <=