aboutsummaryrefslogtreecommitdiffstats
path: root/stylesheets/lfs-xsl/docbook-xsl-1.78.1/extensions/xslt.py
diff options
context:
space:
mode:
authorMatthew Burgess <matthew@linuxfromscratch.org>2013-10-08 20:03:29 +0000
committerMatthew Burgess <matthew@linuxfromscratch.org>2013-10-08 20:03:29 +0000
commit15c7d39533a1eb1da0748011f3378fd0f02ed14d (patch)
treea7ed12df60c5ffd4d00a570804c51470bfb8b0f5 /stylesheets/lfs-xsl/docbook-xsl-1.78.1/extensions/xslt.py
parent09a35dd7178070f01a7961d2ded39e11ba2aac83 (diff)
Update stylesheets to docbook-xsl-1.78.1.
git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@10355 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689
Diffstat (limited to 'stylesheets/lfs-xsl/docbook-xsl-1.78.1/extensions/xslt.py')
-rw-r--r--stylesheets/lfs-xsl/docbook-xsl-1.78.1/extensions/xslt.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/stylesheets/lfs-xsl/docbook-xsl-1.78.1/extensions/xslt.py b/stylesheets/lfs-xsl/docbook-xsl-1.78.1/extensions/xslt.py
new file mode 100644
index 000000000..c712f65fb
--- /dev/null
+++ b/stylesheets/lfs-xsl/docbook-xsl-1.78.1/extensions/xslt.py
@@ -0,0 +1,84 @@
+#!/usr/bin/python -u
+# $Id: xslt.py 8353 2009-03-17 16:57:50Z mzjn $
+
+import sys
+import libxml2
+import libxslt
+from docbook import adjustColumnWidths
+
+# Check the arguments
+usage = "Usage: %s xmlfile.xml xslfile.xsl [outputfile] [param1=val [param2=val]...]" % sys.argv[0]
+
+xmlfile = None
+xslfile = None
+outfile = "-"
+params = {}
+
+try:
+ xmlfile = sys.argv[1]
+ xslfile = sys.argv[2]
+except IndexError:
+ print usage
+ sys.exit(1)
+
+def quote(astring):
+ if astring.find("'") < 0:
+ return "'" + astring + "'"
+ else:
+ return '"' + astring + '"'
+
+try:
+ outfile = sys.argv[3]
+ if outfile.find("=") > 0:
+ name, value = outfile.split("=", 2)
+ params[name] = quote(value)
+ outfile = None
+
+ count = 4
+ while (sys.argv[count]):
+ try:
+ name, value = sys.argv[count].split("=", 2)
+ if params.has_key(name):
+ print "Warning: '%s' re-specified; replacing value" % name
+ params[name] = quote(value)
+ except ValueError:
+ print "Invalid parameter specification: '" + sys.argv[count] + "'"
+ print usage
+ sys.exit(1)
+ count = count+1
+except IndexError:
+ pass
+
+# ======================================================================
+# Memory debug specific
+# libxml2.debugMemory(1)
+
+# Setup environment
+libxml2.lineNumbersDefault(1)
+libxml2.substituteEntitiesDefault(1)
+libxslt.registerExtModuleFunction("adjustColumnWidths",
+ "http://nwalsh.com/xslt/ext/xsltproc/python/Table",
+ adjustColumnWidths)
+
+# Initialize and run
+styledoc = libxml2.parseFile(xslfile)
+style = libxslt.parseStylesheetDoc(styledoc)
+doc = libxml2.parseFile(xmlfile)
+result = style.applyStylesheet(doc, params)
+
+# Save the result
+if outfile:
+ style.saveResultToFilename(outfile, result, 0)
+else:
+ print result
+
+# Free things up
+style.freeStylesheet()
+doc.freeDoc()
+result.freeDoc()
+
+# Memory debug specific
+#libxslt.cleanup()
+#if libxml2.debugMemory(1) != 0:
+# print "Memory leak %d bytes" % (libxml2.debugMemory(1))
+# libxml2.dumpMemory()