summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2010-01-28 12:41:03 +0000
committerWill Thompson <will.thompson@collabora.co.uk>2010-01-28 16:10:07 +0000
commit7a859d2944da798a22b79a1b94b7d1ba6b1a94d5 (patch)
tree6916e8d14a099fbb6102dd2220bec83f57d3763c /tools
parent2dabba9c31fc6e81fce8d52f39cab18ab8f7ac68 (diff)
Use the Glorious XIncludator, not identity.xsl
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am4
-rw-r--r--tools/identity.xsl7
-rw-r--r--tools/xincludator.py39
3 files changed, 41 insertions, 9 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 6ab2d9a9d..71bede79e 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -9,11 +9,11 @@ EXTRA_DIST = \
glib-gtypes-generator.py \
glib-interfaces-gen.py \
glib-signals-marshal-gen.py \
- identity.xsl \
lcov.am \
libglibcodegen.py \
libtpcodegen.py \
- telepathy.am
+ telepathy.am \
+ xincludator.py
CLEANFILES = *.pyc *.pyo
diff --git a/tools/identity.xsl b/tools/identity.xsl
deleted file mode 100644
index 6630f84de..000000000
--- a/tools/identity.xsl
+++ /dev/null
@@ -1,7 +0,0 @@
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:template match="@*|node()">
- <xsl:copy>
- <xsl:apply-templates select="@*|node()"/>
- </xsl:copy>
- </xsl:template>
-</xsl:stylesheet>
diff --git a/tools/xincludator.py b/tools/xincludator.py
new file mode 100644
index 000000000..63e106ace
--- /dev/null
+++ b/tools/xincludator.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+
+from sys import argv, stdout, stderr
+import codecs, locale
+import os
+import xml.dom.minidom
+
+stdout = codecs.getwriter('utf-8')(stdout)
+
+NS_XI = 'http://www.w3.org/2001/XInclude'
+
+def xincludate(dom, base, dropns = []):
+ remove_attrs = []
+ for i in xrange(dom.documentElement.attributes.length):
+ attr = dom.documentElement.attributes.item(i)
+ if attr.prefix == 'xmlns':
+ if attr.localName in dropns:
+ remove_attrs.append(attr)
+ else:
+ dropns.append(attr.localName)
+ for attr in remove_attrs:
+ dom.documentElement.removeAttributeNode(attr)
+ for include in dom.getElementsByTagNameNS(NS_XI, 'include'):
+ href = include.getAttribute('href')
+ # FIXME: assumes Unixy paths
+ filename = os.path.join(os.path.dirname(base), href)
+ subdom = xml.dom.minidom.parse(filename)
+ xincludate(subdom, filename, dropns)
+ if './' in href:
+ subdom.documentElement.setAttribute('xml:base', href)
+ include.parentNode.replaceChild(subdom.documentElement, include)
+
+if __name__ == '__main__':
+ argv = argv[1:]
+ dom = xml.dom.minidom.parse(argv[0])
+ xincludate(dom, argv[0])
+ xml = dom.toxml()
+ stdout.write(xml)
+ stdout.write('\n')