1.1 --- a/README.txt Thu Aug 18 15:56:06 2005 +0000
1.2 +++ b/README.txt Thu Aug 18 15:57:13 2005 +0000
1.3 @@ -45,10 +45,12 @@
1.4 New in XSLTools 0.2 (Changes since XSLTools 0.1)
1.5 ------------------------------------------------
1.6
1.7 -Added XMLTable.
1.8 +Made a new XSLTools package and moved XSLOutput into it.
1.9 +Added XMLTable (to the XSLTools package).
1.10 Changed in-page requests to contain proper POST data.
1.11 Added Debian package support.
1.12 Added missing COPYING.txt file.
1.13 +Renamed the scripts to avoid naming issues in system-wide installations.
1.14
1.15 Notes on In-Page Update Functionality
1.16 -------------------------------------
1.17 @@ -132,7 +134,8 @@
1.18 Release Procedures
1.19 ------------------
1.20
1.21 -Update the XSLOutput.py and XSLForms/__init__.py __version__ attributes.
1.22 +Update the XSLTools/__init__.py and XSLForms/__init__.py __version__
1.23 +attributes.
1.24 Change the version number and package filename/directory in the documentation.
1.25 Change code examples in the documentation if appropriate.
1.26 Update the release notes (see above).
2.1 --- a/XMLTable.py Thu Aug 18 15:56:06 2005 +0000
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,92 +0,0 @@
2.4 -#!/usr/bin/env python
2.5 -
2.6 -"A list of tuples to XML document converter."
2.7 -
2.8 -import libxml2dom
2.9 -from UserDict import UserDict
2.10 -
2.11 -class OrderedDict(UserDict):
2.12 -
2.13 - "A dictionary with keys in the order in which they were given."
2.14 -
2.15 - def __init__(self, *args):
2.16 - UserDict.__init__(self, *args)
2.17 - self._keys = self.data.keys()
2.18 -
2.19 - def __setitem__(self, key, value):
2.20 - UserDict.__setitem__(self, key, value)
2.21 - if key not in self._keys:
2.22 - self._keys.append(key)
2.23 -
2.24 - def __delitem__(self, key):
2.25 - UserDict.__delitem__(self, key)
2.26 - del self._keys[key]
2.27 -
2.28 - def keys(self):
2.29 - return self._keys
2.30 -
2.31 - def items(self):
2.32 - l = []
2.33 - for key in self._keys:
2.34 - l.append((key, self.data[key]))
2.35 - return l
2.36 -
2.37 - def values(self):
2.38 - return [value for key, value in self.items()]
2.39 -
2.40 -class Converter:
2.41 - def __init__(self, ns=None, prefix="", doc=None, root=None):
2.42 - self.ns = ns
2.43 - self.prefix = prefix
2.44 - if doc is not None:
2.45 - self.doc = doc
2.46 - else:
2.47 - self.doc = libxml2dom.createDocument(ns, prefix+"table", None)
2.48 - if root is not None:
2.49 - self.root = root
2.50 - else:
2.51 - self.root = self.doc.xpath("*")[0]
2.52 -
2.53 - def add_rows(self, rows):
2.54 - for row in rows:
2.55 - self.add_row(row)
2.56 -
2.57 - def add_row(self, row, index=-1, row_element_name="row", use_key_as_element_name=0):
2.58 - row_element = self.doc.createElementNS(self.ns, self.prefix+row_element_name)
2.59 - if index == -1:
2.60 - self.root.appendChild(row_element)
2.61 - else:
2.62 - self.root.insertBefore(row_element, self.root.xpath("*[%s]" % (index + 1))[0])
2.63 -
2.64 - # Permit dictionaries.
2.65 -
2.66 - if hasattr(row, "items"):
2.67 - for name, value in row.items():
2.68 - if use_key_as_element_name:
2.69 - column_element = self.doc.createElementNS(self.ns, self.prefix+unicode(name))
2.70 - else:
2.71 - column_element = self.doc.createElementNS(self.ns, self.prefix+"column")
2.72 - column_element.setAttributeNS(self.ns, self.prefix+"name", unicode(name))
2.73 - row_element.appendChild(column_element)
2.74 - text = self.doc.createTextNode(unicode(value))
2.75 - column_element.appendChild(text)
2.76 -
2.77 - # As well as sequences.
2.78 -
2.79 - else:
2.80 - for column in row:
2.81 - column_element = self.doc.createElementNS(self.ns, self.prefix+"column")
2.82 - row_element.appendChild(column_element)
2.83 - text = self.doc.createTextNode(unicode(column))
2.84 - column_element.appendChild(text)
2.85 -
2.86 -if __name__ == "__main__":
2.87 - from rdflib.TripleStore import TripleStore
2.88 - import sys
2.89 - s = TripleStore()
2.90 - s.load(sys.argv[1])
2.91 - converter = Converter()
2.92 - converter.add_rows(s.triples((None, None, None)))
2.93 - libxml2dom.toStream(converter.doc, sys.stdout)
2.94 -
2.95 -# vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/XSLOutput.py Thu Aug 18 15:56:06 2005 +0000
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,128 +0,0 @@
3.4 -#!/usr/bin/env python
3.5 -
3.6 -"""
3.7 -XSL output classes and functions.
3.8 -
3.9 -Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk>
3.10 -
3.11 -This library is free software; you can redistribute it and/or
3.12 -modify it under the terms of the GNU Lesser General Public
3.13 -License as published by the Free Software Foundation; either
3.14 -version 2.1 of the License, or (at your option) any later version.
3.15 -
3.16 -This library is distributed in the hope that it will be useful,
3.17 -but WITHOUT ANY WARRANTY; without even the implied warranty of
3.18 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3.19 -Lesser General Public License for more details.
3.20 -
3.21 -You should have received a copy of the GNU Lesser General Public
3.22 -License along with this library; if not, write to the Free Software
3.23 -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3.24 -"""
3.25 -
3.26 -__version__ = "0.2"
3.27 -
3.28 -# NOTE: Make this use other implementations, too.
3.29 -
3.30 -import libxsltmod
3.31 -import libxml2dom
3.32 -
3.33 -class OutputError(Exception):
3.34 - pass
3.35 -
3.36 -class Processor:
3.37 -
3.38 - """
3.39 - A handler which can prepare output for an XMLTools2 template.
3.40 - """
3.41 -
3.42 - def __init__(self, filenames, references=None, parameters=None):
3.43 -
3.44 - """
3.45 - Initialise the handler with the 'filenames' of stylesheets producing the
3.46 - final output, a 'references' dictionary indicating related stylesheets.
3.47 - Additional 'parameters' may also be specified as a dictionary.
3.48 - """
3.49 -
3.50 - self.references = references or {}
3.51 - self.parameters = parameters or {}
3.52 -
3.53 - # Remember the stylesheet documents.
3.54 -
3.55 - self.stylesheets = []
3.56 - for filename in filenames:
3.57 - doc = libxml2dom.macrolib.parseFile(filename)
3.58 - self.stylesheets.append(libxsltmod.xsltParseStylesheetDoc(doc))
3.59 -
3.60 - def __del__(self):
3.61 -
3.62 - """
3.63 - Tidy up the stylesheet documents.
3.64 - """
3.65 -
3.66 - for stylesheet in self.stylesheets:
3.67 - libxsltmod.xsltFreeStylesheet(stylesheet)
3.68 -
3.69 - def send_output(self, stream, encoding, document):
3.70 -
3.71 - """
3.72 - Send output to the given 'stream' using the given output encoding for
3.73 - the given 'document'.
3.74 - """
3.75 -
3.76 - result = self.get_result(document)
3.77 -
3.78 - if result is not None:
3.79 - stream.write(result.toString(encoding))
3.80 - else:
3.81 - raise OutputError, "Transformation failed."
3.82 -
3.83 - def get_result(self, document):
3.84 -
3.85 - """
3.86 - Return a transformed document produced from the object's stylesheets and
3.87 - the given 'document'.
3.88 - """
3.89 -
3.90 - result = self._get_result(document)
3.91 -
3.92 - if result is not None:
3.93 - return libxml2dom.adoptNodes([result])[0]
3.94 - else:
3.95 - raise OutputError, "Transformation failed."
3.96 -
3.97 - def _get_result(self, document):
3.98 -
3.99 - """
3.100 - Return a transformation of the given 'document'.
3.101 - """
3.102 -
3.103 - if hasattr(document, "as_native_node"):
3.104 - document = document.as_native_node()
3.105 -
3.106 - # Transform the localised instance into the final output.
3.107 -
3.108 - parameters = {}
3.109 - for name, reference in self.references.items():
3.110 - parameters[name.encode("utf-8")] = ("document('%s')" % self._quote(reference)).encode("utf-8")
3.111 - for name, parameter in self.parameters.items():
3.112 - parameters[name.encode("utf-8")] = ("'%s'" % self._quote(parameter)).encode("utf-8")
3.113 - #print "**", repr(parameters)
3.114 -
3.115 - last_result = document
3.116 - for stylesheet in self.stylesheets:
3.117 - result = libxsltmod.xsltApplyStylesheet(stylesheet, last_result, parameters)
3.118 - if last_result is not None:
3.119 - last_result = result
3.120 - else:
3.121 - raise OutputError, "Transformation failed."
3.122 -
3.123 - return result
3.124 -
3.125 - def _quote(self, s):
3.126 -
3.127 - "Make the given parameter string 's' palatable for libxslt."
3.128 -
3.129 - return s.replace("'", "%27")
3.130 -
3.131 -# vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/setup.py Thu Aug 18 15:56:06 2005 +0000
4.2 +++ b/setup.py Thu Aug 18 15:57:13 2005 +0000
4.3 @@ -11,8 +11,7 @@
4.4 author_email = "paul@boddie.org.uk",
4.5 url = "http://www.boddie.org.uk/python/XSLTools.html",
4.6 version = XSLForms.__version__,
4.7 - packages = ["XSLForms"],
4.8 - py_modules = ["XMLTable", "XSLOutput"],
4.9 + packages = ["XSLForms", "XSLTools"],
4.10 package_data = {"XSLForms" : ["XSL/*.xsl"]},
4.11 - scripts = ["scripts/extract.py", "scripts/output.py", "scripts/prepare.py"]
4.12 + scripts = ["scripts/xslform_extract.py", "scripts/xslform_output.py", "scripts/xslform_prepare.py"]
4.13 )