#!/usr/bin/python2.3

import libxml2

# we need: export PYTHONPATH="/usr/lib/python2.3:/home/wxwindows/lib/python/:/home/wxwindows/pythonlibs/lib/python2.3/site-packages/:/home/wxwindows/pythonlibs/usr/lib/python2.3/site-packages/"

class XPathElem:
  def __init__(self, node):
    self.node = node
  def value(self, path): return self.node.xpathEval('string(' + path + ')')
  def nodes(self, path): return [ XPathElem(x) for x in self.node.xpathEval(path) ]
  def test(self, path): return self.node.xpathEval('boolean(' + path + ')')

catsroot = XPathElem(libxml2.parseFile("categories.xml"))
classroot = XPathElem(libxml2.parseFile("classes.xml"))

print '<html><body><h1>Classes by Category</h1>'

for mycat in catsroot.nodes ('/categories/category'):
  name = mycat.value('@name')
  print '<h2>' + name + "</h2>"
  print mycat.value('description')
  print '<table>'

  for myclass in classroot.nodes ('/classes/class[category=\'' + name + '\']'):
    print '<tr><td>' + myclass.value('@name') + '</td><td>' + myclass.value('shortdesc') + '</td></tr>'

  print '</table>'

#  for platform in myclass.nodes ('supported/platform'):
#    mydict[platform.value('@name')] = platform.value('@status')
#
#  print '<tr><td>' + myclass.value('@name')
#  for platform in platforms:
#    print '<td>' 
#    if mydict.has_key(platform):
#      print mydict[platform]

print '</body></html>'

