diff --git a/common.mk.in b/common.mk.in index b918b39..61c39fe 100644 --- a/common.mk.in +++ b/common.mk.in @@ -23,15 +23,15 @@ else rm -rf $(OUTDIR) endif -XSLTARGS=g_date=`date -I` g_time=`date +%H:%M:%S` g_outdir="$(OUTDIR)" \ - g_datetime="`date --rfc-3339=seconds`" g_pwd="$$(pwd)" g_root="$(ROOT)" -SAXON = /users/www/saxon9/saxon9.bin +XSLTARGS=g_date="`date -I`" g_time="`date +%H:%M:%S`" g_outdir="$(OUTDIR)" \ + g_datetime="`date --rfc-3339=seconds`" g_pwd="`pwd`" g_root="$(ROOT)" +XSLTPROC = $(ROOT)/scripts/xsltproc.py $(OUTDIR)%.html: %.xml $(ROOT)/csc.dtd $(ROOT)/xsl/*.xsl directory.xml $(ROOT)/menu.xml - $(SAXON) -o $@ $< $(ROOT)/xsl/html.xsl $(XSLTARGS) + $(XSLTPROC) $< $(ROOT)/xsl/html.xsl $@ $(XSLTARGS) $(OUTDIR)%.atom: %.xml xsl/atom.xsl - $(SAXON) -o $@ $< $(ROOT)/xsl/atom.xsl $(XSLTARGS) + $(XSLTPROC) $< $(ROOT)/xsl/atom.xsl $@ $(XSLTARGS) $(OUTDIR)%.ics: %.xml perl scripts/xml2ics.pl $< > $@ diff --git a/scripts/xsltproc.py b/scripts/xsltproc.py new file mode 100755 index 0000000..3619a8a --- /dev/null +++ b/scripts/xsltproc.py @@ -0,0 +1,82 @@ +#!/usr/bin/python2.4 +import os, sys, re, urllib, libxml2, libxslt + +# +# globals +# +cscUri = "http://csclub.uwaterloo.ca/xsltproc" + +# +# csc:encode-for-uri +# +def cscEncodeForUri(ctx, str): + if type(str) == type([]): + str = libxml2.xmlNode(str[0]).getContent() + print urllib.quote(str) + return urllib.quote(str) + +# +# csc:term +# +def cscTerm(ctx, str): + if type(str) == type([]): + str = libxml2.xmlNode(str[0]).getContent() + + try: + # YYYY-MM-DD + (year, month, day) = re.findall("^([0-9]+)-([0-9]+)-([0-9]+)$", str)[0] + month = int(month) + if month >= 1 and month <= 4: + return "Winter " + year + elif month >= 5 and month <= 8: + return "Spring " + year + elif month >= 9 and month <= 12: + return "Fall " + year + else: + print "Invalid month '" + month + "'" + except: + print "Invalid term '" + str + "'" + +# +# csc:email +# +def cscEmail(ctx, str): + return "_EMAIL_TODO_" + +# +# main +# + +# check argv +if len(sys.argv) < 4: + print "Usage: xsltproc.py input-file style-sheet output-file [params...]" + sys.exit(1) +inFile = sys.argv[1] +xsltFile = sys.argv[2] +outFile = sys.argv[3] +rawParams = sys.argv[4:] + +# check params +params = {} +for p in rawParams: + p = p.split("=") + if len(p) == 1: + print "Missing value for parameter " + p[0] + sys.exit(1) + params[p[0]] = "'" + p[1] + "'" + +try: + # register extensions + libxslt.registerExtModuleFunction("encode-for-uri", cscUri, cscEncodeForUri) + libxslt.registerExtModuleFunction("term", cscUri, cscTerm) + libxslt.registerExtModuleFunction("email", cscUri, cscEmail) + + # parse xml/xslt and apply style-sheet + style = libxslt.parseStylesheetFile(xsltFile) + doc = libxml2.parseFile(inFile) + res = style.applyStylesheet(doc, params) + style.saveResultToFilename(outFile, res, 0) + +except: + print "Unexpected error:", sys.exc_info()[0] + sys.exit(1) diff --git a/xsl/atom.xsl b/xsl/atom.xsl index d1c0f6b..289e1a7 100644 --- a/xsl/atom.xsl +++ b/xsl/atom.xsl @@ -1,11 +1,9 @@ - + xmlns:csc="http://csclub.uwaterloo.ca/xsltproc"> diff --git a/xsl/common.xsl b/xsl/common.xsl index 0a2c406..24b4780 100644 --- a/xsl/common.xsl +++ b/xsl/common.xsl @@ -1,11 +1,9 @@ - + xmlns:csc="http://csclub.uwaterloo.ca/xsltproc"> diff --git a/xsl/directory.xsl b/xsl/directory.xsl index 2a791f7..585994e 100644 --- a/xsl/directory.xsl +++ b/xsl/directory.xsl @@ -1,11 +1,9 @@ - + xmlns:csc="http://csclub.uwaterloo.ca/xsltproc"> diff --git a/xsl/events.xsl b/xsl/events.xsl index 5b5c5af..3619473 100644 --- a/xsl/events.xsl +++ b/xsl/events.xsl @@ -1,11 +1,9 @@ - + xmlns:csc="http://csclub.uwaterloo.ca/xsltproc"> @@ -71,7 +69,7 @@ - @@ -96,7 +94,7 @@ - + @@ -111,7 +109,7 @@

- @@ -128,7 +126,7 @@ - +
diff --git a/xsl/exec.xsl b/xsl/exec.xsl index 8357b32..810cf0e 100644 --- a/xsl/exec.xsl +++ b/xsl/exec.xsl @@ -1,11 +1,9 @@ - + xmlns:csc="http://csclub.uwaterloo.ca/xsltproc">

Elected positions

diff --git a/xsl/functions.xsl b/xsl/functions.xsl index 22595ef..b9558a6 100644 --- a/xsl/functions.xsl +++ b/xsl/functions.xsl @@ -1,37 +1,9 @@ - - - - - - - - - - - - - - - - - - - - - Winter - Spring - Fall - - - - + xmlns:csc="http://csclub.uwaterloo.ca/xsltproc">

Please consider donating to the diff --git a/xsl/html.xsl b/xsl/html.xsl index 31baecc..bd0a932 100644 --- a/xsl/html.xsl +++ b/xsl/html.xsl @@ -1,11 +1,9 @@ - + xmlns:csc="http://csclub.uwaterloo.ca/xsltproc"> diff --git a/xsl/media.xsl b/xsl/media.xsl index ce1f403..9fbac93 100644 --- a/xsl/media.xsl +++ b/xsl/media.xsl @@ -1,11 +1,9 @@ - + xmlns:csc="http://csclub.uwaterloo.ca/xsltproc"> @@ -54,8 +52,8 @@ - - + @@ -118,7 +116,7 @@