[Home] [By Thread] [By Date] [Recent Entries]
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> </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(., '+', @state))[1])]"> <xsl:sort select="@state"/> <xsl:copy-of select="state-objective" /><xsl:text> </ 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
|

Cart



