Muenchian Method - count items in group
This is an open discussion with 3 replies, filed under General.
Search
I think I figured it out on my own. Can somebody please comment if it’s the right way.
Cherries: <xsl:value-of select="count(key('fruits-by-day',date)/fruit/item[@handle='cherry'])" /> Bananas: <xsl:value-of select="count(key('fruits-by-day',date)/fruit/item[@handle='banana'])" /> Total: <xsl:value-of select="count(key('fruits-by-day', date))" />
If I test it, the numbers add up…
Looks good to me!
I learned that it’s always good to use keys if you are doing some kind of search on your data. (One reason is performance, by the way.)
That will work if you know all the types of fruit that will be entered. When an unexpected type is entered your total won’t match the sum of the enumerated fruit. And you will have some zero counts on dates that don’t include a particular type of fruit.
Create an account or sign in to comment.
I am implementing Muenchian Method to group entries by date and it is confusing. I get the list of fruits grouped by day in a list. Please see the sample data below… How can I count how many bananas and cherries that are eaten in each day.
This is the xsl: