source: stylesheets/lfs-xsl/docbook-xsl-1.78.1/extensions/xslt.py@ 15c7d39

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 9.0 9.1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since 15c7d39 was 15c7d39, checked in by Matthew Burgess <matthew@…>, 11 years ago

Update stylesheets to docbook-xsl-1.78.1.

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@10355 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#!/usr/bin/python -u
2# $Id: xslt.py 8353 2009-03-17 16:57:50Z mzjn $
3
4import sys
5import libxml2
6import libxslt
7from docbook import adjustColumnWidths
8
9# Check the arguments
10usage = "Usage: %s xmlfile.xml xslfile.xsl [outputfile] [param1=val [param2=val]...]" % sys.argv[0]
11
12xmlfile = None
13xslfile = None
14outfile = "-"
15params = {}
16
17try:
18 xmlfile = sys.argv[1]
19 xslfile = sys.argv[2]
20except IndexError:
21 print usage
22 sys.exit(1)
23
24def quote(astring):
25 if astring.find("'") < 0:
26 return "'" + astring + "'"
27 else:
28 return '"' + astring + '"'
29
30try:
31 outfile = sys.argv[3]
32 if outfile.find("=") > 0:
33 name, value = outfile.split("=", 2)
34 params[name] = quote(value)
35 outfile = None
36
37 count = 4
38 while (sys.argv[count]):
39 try:
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)
44 except ValueError:
45 print "Invalid parameter specification: '" + sys.argv[count] + "'"
46 print usage
47 sys.exit(1)
48 count = count+1
49except IndexError:
50 pass
51
52# ======================================================================
53# Memory debug specific
54# libxml2.debugMemory(1)
55
56# Setup environment
57libxml2.lineNumbersDefault(1)
58libxml2.substituteEntitiesDefault(1)
59libxslt.registerExtModuleFunction("adjustColumnWidths",
60 "http://nwalsh.com/xslt/ext/xsltproc/python/Table",
61 adjustColumnWidths)
62
63# Initialize and run
64styledoc = libxml2.parseFile(xslfile)
65style = libxslt.parseStylesheetDoc(styledoc)
66doc = libxml2.parseFile(xmlfile)
67result = style.applyStylesheet(doc, params)
68
69# Save the result
70if outfile:
71 style.saveResultToFilename(outfile, result, 0)
72else:
73 print result
74
75# Free things up
76style.freeStylesheet()
77doc.freeDoc()
78result.freeDoc()
79
80# Memory debug specific
81#libxslt.cleanup()
82#if libxml2.debugMemory(1) != 0:
83# print "Memory leak %d bytes" % (libxml2.debugMemory(1))
84# libxml2.dumpMemory()
Note: See TracBrowser for help on using the repository browser.