Section Grouping (XSL Newbie!)
Hello!
I am trying to 'run a transform', I think the lingo is, and am coming up against a problem.
I want to display a list of programs, and the categories below each of those programs.
The XML file that I am pulling all the data from has LOTS of lines of the same program, and lots of lines of the same category underneath each program.
The problem I am running up against (when attempting to display unique values) is that there are categories with the same name under different programs. What happens when I run my transform is that those 'duplicate' categories aren't shown.
For example, I want:
Program 1
AAA Cat
BBB Cat
Program 2
CCC Cat
Program 3
AAA Cat
DDD Cat
and instead, I get:
Program 1
AAA Cat
BBB Cat
Program 2
CCC Cat
Program 3
DDD Cat
(the second AAA is removed)
My xsl looks like:
<xsl:variable name="programs" select="//PROGRAM[not(.=preceding::PROGRAM)]"/>
<xsl:for-each select="$programs">
<xsl:variable name="program" select="."/>
<xsl:element name="section">
<xsl:element name="title">
<xsl:value-of select="$program"/>
</xsl:element>
<xsl:variable name="categories"
select="//CATEGORY[not(.=preceding::CATEGORY) and preceding-sibling::PROGRAM = $program]"/>
<xsl:for-each select="$categories">
<xsl:variable name="category" select="."/>
<xsl:element name="section">
<xsl:element name="title">
<xsl:value-of select="$category"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
Any suggestions appreciated!
Thanks,
G.
|