[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Multilevel Muenchian grouping -- Why doesn't this work
I want to group some entries first by year, and then by month. My ideal output is: <h2>2003</h2> <h3>2</h3> <ul>...</ul> <h3>1</h3> <ul>...</ul> <h2>2002</h2> <h3>12</h3> <ul>...</ul> ... The XSLT I've come up with, with help from Jeni Tennison's site, is this (relevant excerpt): <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" doctype-public="-//W3C//DTD HTML 4.01//EN"/> <xsl:key name="entry-year" match="entry" use="date/year"/> xsl:key name="entry-month" match="entry" use="concat(date/year, date/month)"/> <xsl:for-each select="entry[count(. | key('entry-year', date/year)[1]) = 1]"> <xsl:sort select="date/year" data-type="number" order="descending"/> <h2><xsl:value-of select="date/year"/></h2> <xsl:for-each select="key('entry-year', date/year)[count(. | key('entry-month', concat(date/year, date/month))[1]) = 1]"> <xsl:sort select="date/month" data-type="number" order="descending"/> <h3><xsl:value-of select="date/month"/></h3> <ul> <xsl:for-each select="key('entry-month', concat(date/year, date/month))"> [...] </xsl:for-each> </ul> </xsl:for-each> </xsl:for-each> The output this gets me on the input included below is: <h2>2003</h2> <h3>2</h3> <ul></ul> <h3>1</h3> <ul></ul> <h3>1</h3> <ul></ul> <h3>1</h3> <ul></ul> <h3>1</h3> <ul></ul> <h2>2002</h2> <h3>11</h3> <ul></ul> <h3>11</h3> <ul></ul> I don't understand why all the months are showing up repeatedly, and nothing inside at all. The (relevant excerpt from the) input file looks like this: <?xml version="1.0" encoding="UTF-8"?> <booklog> <entry id="159"> <date> <year>2003</year> <month>2</month> <day>5</day> </date> </entry> <entry id="160"> <date> <year>2003</year> <month>1</month> <day>9</day> </date> </entry> <entry id="161"> <date> <year>2003</year> <month>1</month> <day>10</day> </date> </entry> <entry id="162"> <date> <year>2003</year> <month>1</month> <day>11</day> </date> </entry> <entry id="163"> <date> <year>2003</year> <month>1</month> <day>24</day> </date> </entry> <entry id="151"> <date> <year>2002</year> <month>11</month> <day>12</day> </date> </entry> <entry id="150"> <date> <year>2002</year> <month>11</month> <day>9</day> </date> </entry> </booklog> -- Mike Kozlowski http://www.klio.org/mlk/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|