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 $< > $@
--- /dev/null
+#!/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)
<?xml version='1.0'?>
-<xsl:stylesheet version="2.0"
+<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:fn="http://www.w3.org/2005/xpath-functions"
- xmlns:csc="http://csclub.uwaterloo.ca/xslt">
+ xmlns:csc="http://csclub.uwaterloo.ca/xsltproc">
<xsl:param name="g_datetime" required="yes" />
<?xml version='1.0'?>
-<xsl:stylesheet version="2.0"
+<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:fn="http://www.w3.org/2005/xpath-functions"
- xmlns:csc="http://csclub.uwaterloo.ca/xslt">
+ xmlns:csc="http://csclub.uwaterloo.ca/xsltproc">
<xsl:template match="cscpage">
<html>
<?xml version='1.0'?>
-<xsl:stylesheet version="2.0"
+<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:fn="http://www.w3.org/2005/xpath-functions"
- xmlns:csc="http://csclub.uwaterloo.ca/xslt">
+ xmlns:csc="http://csclub.uwaterloo.ca/xsltproc">
<xsl:template match="directory">
<xsl:variable name="href">
<?xml version='1.0'?>
-<xsl:stylesheet version="2.0"
+<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:fn="http://www.w3.org/2005/xpath-functions"
- xmlns:csc="http://csclub.uwaterloo.ca/xslt">
+ xmlns:csc="http://csclub.uwaterloo.ca/xsltproc">
<xsl:template name="events">
<tr>
</xsl:template>
<xsl:template match="eventitem">
- <xsl:result-document method="xml" encoding="ISO-8859-1"
+ <xsl:document method="xml" encoding="ISO-8859-1"
doctype-public="-//W3C//DTD XHTML 1.1//EN"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
href="{translate(concat($g_outdir, @room, '-', @date, '-', @time, '.html'), ' ', '_')}">
<xsl:call-template name="footer" />
</div></body>
</html>
- </xsl:result-document>
+ </xsl:document>
</xsl:template>
<xsl:template match="generate-event-files">
<p><a href="{translate(concat('old-',csc:term(@date), '.html'), ' ', '_')}">
<xsl:value-of select="csc:term(@date)" />
</a></p>
- <xsl:result-document method="xml" encoding="ISO-8859-1"
+ <xsl:document method="xml" encoding="ISO-8859-1"
doctype-public="-//W3C//DTD XHTML 1.1//EN"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
href="{translate(concat($g_outdir, 'old-', csc:term(@date), '.html'), ' ', '_')}">
<xsl:call-template name="footer" />
</div></body>
</html>
- </xsl:result-document>
+ </xsl:document>
</xsl:if>
</xsl:for-each>
</xsl:template>
<?xml version='1.0'?>
-<xsl:stylesheet version="2.0"
+<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:fn="http://www.w3.org/2005/xpath-functions"
- xmlns:csc="http://csclub.uwaterloo.ca/xslt">
+ xmlns:csc="http://csclub.uwaterloo.ca/xsltproc">
<xsl:template match="execlist">
<h3>Elected positions</h3>
<?xml version='1.0'?>
-<xsl:stylesheet version="2.0"
+<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:fn="http://www.w3.org/2005/xpath-functions"
- xmlns:csc="http://csclub.uwaterloo.ca/xslt">
-
-<xsl:function name="csc:term" as="xs:string">
- <xsl:param name="date" />
- <xsl:variable name="date_year" as="xs:integer">
- <xsl:analyze-string select="$date" regex="([0-9]+)-[0-9]+-[0-9]+">
- <xsl:matching-substring>
- <xsl:value-of select="regex-group(1)" />
- </xsl:matching-substring>
- </xsl:analyze-string>
- </xsl:variable>
- <xsl:variable name="date_month" as="xs:integer">
- <xsl:analyze-string select="$date" regex="[0-9]+-([0-9]+)-[0-9]+">
- <xsl:matching-substring>
- <xsl:value-of select="regex-group(1)" />
- </xsl:matching-substring>
- </xsl:analyze-string>
- </xsl:variable>
- <xsl:variable name="term_text">
- <xsl:choose>
- <xsl:when test="$date_month ge 1 and $date_month le 4">Winter </xsl:when>
- <xsl:when test="$date_month ge 5 and $date_month le 8">Spring </xsl:when>
- <xsl:when test="$date_month ge 9 and $date_month le 12">Fall </xsl:when>
- </xsl:choose>
- </xsl:variable>
- <xsl:value-of select="concat($term_text, $date_year)" />
-</xsl:function>
+ xmlns:csc="http://csclub.uwaterloo.ca/xsltproc">
<xsl:template name="donate-now">
<p>Please consider <a href="{$g_pre}about/donations.html">donating to the
<?xml version='1.0'?>
-<xsl:stylesheet version="2.0"
+<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:fn="http://www.w3.org/2005/xpath-functions"
- xmlns:csc="http://csclub.uwaterloo.ca/xslt">
+ xmlns:csc="http://csclub.uwaterloo.ca/xsltproc">
<xsl:param name="g_date" required="yes" />
<xsl:param name="g_time" required="yes" />
<?xml version='1.0'?>
-<xsl:stylesheet version="2.0"
+<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:fn="http://www.w3.org/2005/xpath-functions"
- xmlns:csc="http://csclub.uwaterloo.ca/xslt">
+ xmlns:csc="http://csclub.uwaterloo.ca/xsltproc">
<xsl:template match="mediafile">
<xsl:param name="ext" />
<xsl:param name="mirror" />
<xsl:param name="bittorrent" />
<xsl:param name="ads" />
- <xsl:variable name="realurl" select="concat('http://csclub.uwaterloo.ca/media/', fn:encode-for-uri(@title), '.html')" />
- <xsl:result-document method="xml" encoding="ISO-8859-1"
+ <xsl:variable name="realurl" select="concat('http://csclub.uwaterloo.ca/media/', csc:encode-for-uri(@title), '.html')" />
+ <xsl:document method="xml" encoding="ISO-8859-1"
doctype-public="-//W3C//DTD XHTML 1.1//EN"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
href="{concat($g_outdir, @title, $suffix, '.html')}">
<!-- reddit button -->
<script type="text/javascript">
reddit_url = '<xsl:value-of select="$realurl" />';
- reddit_title = '<xsl:value-of select="fn:encode-for-uri(@title)" />';
+ reddit_title = '<xsl:value-of select="csc:encode-for-uri(@title)" />';
</script>
<script src="http://reddit.com/button.js?t=3"
type="text/javascript">
<xsl:call-template name="footer" />
</div></body>
</html>
- </xsl:result-document>
+ </xsl:document>
</xsl:template>
</xsl:stylesheet>
<?xml version='1.0'?>
-<xsl:stylesheet version="2.0"
+<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:fn="http://www.w3.org/2005/xpath-functions"
- xmlns:csc="http://csclub.uwaterloo.ca/xslt">
+ xmlns:csc="http://csclub.uwaterloo.ca/xsltproc">
<xsl:template match="members-this-term">
<p>The members for <xsl:value-of select="csc:term($g_date)" /> are
<?xml version='1.0'?>
-<xsl:stylesheet version="2.0"
+<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:fn="http://www.w3.org/2005/xpath-functions"
- xmlns:csc="http://csclub.uwaterloo.ca/xslt">
+ xmlns:csc="http://csclub.uwaterloo.ca/xsltproc">
<xsl:template match="menuitem">
<xsl:variable name="preabs">
<?xml version='1.0'?>
-<xsl:stylesheet version="2.0"
+<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:csc="http://csclub.uwaterloo.ca/xslt">
+ xmlns:csc="http://csclub.uwaterloo.ca/xsltproc">
<xsl:template match="newsdefs">
<xsl:apply-templates select="newsitem[csc:term(@date) = csc:term($g_date)]">
<p><a href="{translate(concat('old-', csc:term(@date), '.html'), ' ', '_')}">
<xsl:value-of select="csc:term(@date)" />
</a></p>
- <xsl:result-document method="xml" encoding="ISO-8859-1"
+ <xsl:document method="xml" encoding="ISO-8859-1"
doctype-public="-//W3C//DTD XHTML 1.1//EN"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
href="{translate(concat($g_outdir, 'old-', csc:term(@date), '.html'), ' ', '_')}">
<xsl:call-template name="footer" />
</div></body>
</html>
- </xsl:result-document>
+ </xsl:document>
</xsl:if>
</xsl:for-each>
</xsl:template>