Now that we've got a list of all the categories and the number of posts per category we can start looking at what else we need for a tag cloud. Jon's post contains a formula:
For our purposes:
S is the number of posts for the current category.
A is the average number of category "flags" per post. To be clear, I've configured my Posts list to support checking multiple categories - so I can't just use the number of Posts to determine my average.
*hang on, this is where it gets a little crazy*
To help get our values, I created a few XSL Templates:
The first should look familiar. I've turned what we worked on in the last post into a template:

Now, the next one... ouch. Essentially, I needed to add up all of the posts per category. The problem is, XSL doesn't support a running total concept. You can only declare a variable once and then it is what it is - no updating. So, the answer to our problem? Recursive template calls:
To call the CountCategoryFlags, I have another Template:
So - to step through it:
- I'm sending in an index of 1 and a total of 0 to the CountCategoryFlags template
- That comes in to CountCategoryFlags and we call GetPostCountByCategory using the title of the indexed item in the Categories list
- Then, as long as the index isn't the last in the Categories list, we call CountCategoryFlags again this time passing in:
- the current index + 1
- the current total (0) + the number of CategoryFlags we got earlier
- Once we get to the end, we are returning the last value of total which should be the number of category flags in all of our posts.
Still with me?
Now we can assign two variables:
The TotalCategoryFlags simply wraps our GetTotalCategoryFlags.
The AveragePostsPerCategory does the math to give us the average posts per category!
Now we can start looping through our categories again. For each one, we'll want a local variable to store the number of posts for that category:

Then we can actually use the formula Jon gave us:

Once we have the category weight, we can dump the output:
And that's it! There are two things I parameterized:
- BaseFontSize
- CategoryListUrl
If you make those parameters in your Data View, you can actually change them pretty easily in the browser:
And there you have it:

If you haven't already, you can download the .webpart file HERE and import it into your own blog site.