# HG changeset patch # User paulb # Date 1125340086 0 # Node ID 4c968d8c45e15e5ccdc0186b2ed445938df1f2d4 # Parent 433adf239529c2a451d30085dc45358d738f9cb6 [project @ 2005-08-29 18:28:06 by paulb] Renamed write_calendar_for_month to write_month_to_document and added some more attributes to make further processing of calendar XML easier. diff -r 433adf239529 -r 4c968d8c45e1 XSLTools/XMLCalendar.py --- a/XSLTools/XMLCalendar.py Sun Aug 28 23:45:07 2005 +0000 +++ b/XSLTools/XMLCalendar.py Mon Aug 29 18:28:06 2005 +0000 @@ -22,20 +22,23 @@ # XML production functions. -def write_calendar_for_month(doc, year, month): +def write_month_to_document(doc, root, year, month): weeks = monthcalendar(year, month) - month_element = doc.childNodes[-1].appendChild(doc.createElement("month")) - for dates in weeks: + month_element = root.appendChild(doc.createElement("month")) + month_element.setAttribute("number", str(month)) + month_element.setAttribute("year", str(year)) + for numbers in weeks: week_element = month_element.appendChild(doc.createElement("week")) - for date in dates: + for number in numbers: day_element = week_element.appendChild(doc.createElement("day")) - if date != 0: - day_element.setAttribute("date", "%04d%02d%02d" % (year, month, date)) + if number != 0: + day_element.setAttribute("date", "%04d%02d%02d" % (year, month, number)) + day_element.setAttribute("number", str(number)) def get_calendar_for_month(year, month): - d = libxml2dom.createDocument(None, "calendar", None) - write_calendar_for_month(d, year, month) - return d + doc = libxml2dom.createDocument(None, "calendar", None) + write_month_to_document(doc, doc.childNodes[-1], year, month) + return doc if __name__ == "__main__": import sys