2 # $Id: xslt.py 8353 2009-03-17 16:57:50Z mzjn $
7 from docbook import adjustColumnWidths
10 usage = "Usage: %s xmlfile.xml xslfile.xsl [outputfile] [param1=val [param2=val]...]" % sys.argv[0]
25 if astring.find("'") < 0:
26 return "'" + astring + "'"
28 return '"' + astring + '"'
32 if outfile.find("=") > 0:
33 name, value = outfile.split("=", 2)
34 params[name] = quote(value)
38 while (sys.argv[count]):
40 name, value = sys.argv[count].split("=", 2)
41 if params.has_key(name):
42 print "Warning: '%s' re-specified; replacing value" % name
43 params[name] = quote(value)
45 print "Invalid parameter specification: '" + sys.argv[count] + "'"
52 # ======================================================================
53 # Memory debug specific
54 # libxml2.debugMemory(1)
57 libxml2.lineNumbersDefault(1)
58 libxml2.substituteEntitiesDefault(1)
59 libxslt.registerExtModuleFunction("adjustColumnWidths",
60 "http://nwalsh.com/xslt/ext/xsltproc/python/Table",
64 styledoc = libxml2.parseFile(xslfile)
65 style = libxslt.parseStylesheetDoc(styledoc)
66 doc = libxml2.parseFile(xmlfile)
67 result = style.applyStylesheet(doc, params)
71 style.saveResultToFilename(outfile, result, 0)
76 style.freeStylesheet()
80 # Memory debug specific
82 #if libxml2.debugMemory(1) != 0:
83 # print "Memory leak %d bytes" % (libxml2.debugMemory(1))
84 # libxml2.dumpMemory()