The party make-up of council committees - doing it the XML way @psychemedia @CountCulture

Just seen Tony Hirst's  @psychemedia   blog item about Treemapping the party make-up of council committees.  Tony has done inspiring work with various public datasets, using a mixture of Yahoo Pipes, Google Documents and PHP. This latest work uses data from OpenLocally developed by Chris Taggart  @CountCulture

I hadn't seen this site before. The content and presentation are great and  I've yet to see such a program friendly site.  Not only is the data available as json and XML, but the URLs are programmer friendly too: The HTML URL has an alias of 


I set about mimicing Tony's exercise using XML and XQuery/XSLT. The XML version of a page has a .xml suffix, so the XML version of the main page for Bristol is ; For each committee, the XML URL is based on the committee id e.g. the Full Council Meeting is


I decided on a simple tablular visualisation to start with. (I must say I find Tree Maps rather confusing). Here is the unadorned page for Bristol City:

The script transforms the main page and all the committee pages into an intermediate XML structure, so that all parties can be extracted and assigned a color. This intermediate XML is then transformed to HTML. The script is XQuery but could be two XSLT scripts in a pipeline except that doc() is failing in XSLT just now on my server. 

This is the first step:

let $id := request:get-parameter("id","")
let $councilURL := concat("",$id,".xml")
let $council := doc ($councilURL )/council
let $extract := 
   element council {
     for $committee in $council/committees/committee
       element committee {
         let $committeeURL := concat("",$committee/id,".xml")
         for $member in doc($committeeURL)/committee/members/member
            element member {
                attribute name {concat($member/first-name," ",$member/last-name)},
                attribute party {$member/party}


The next step extracts all the Parties and assigns them a colour - known parties from a configuration table, unknown ones a random color. Finally the committees are ordered by size and output as a table, using  the style attribute of a div to generate the bar charts.

Thanks to Chris for making me feel welcome on his site - a rare experience.  Next task to generate KML from the index page - what great little teaching examples, especially when I can fix XSLT.  I'm becoming a bigger fan of XSLT every day.