id = None
attrs = child.attributes
+ attrs_to_remove = []
if not attrs is None:
for i in range(attrs.length):
attr = attrs.item(0)
- if attr.namespaceURI == "http://template.sesse.net/" or attr.name == "id":
+ if attr.namespaceURI == "http://template.sesse.net/" and attr.localName == "id":
id = attr.value
if clean:
- child.removeAttribute(attr.name)
+ attrs_to_remove.append(attr.name)
+ if attr.name.startswith("xmlns:") and attr.value == "http://template.sesse.net/" and clean:
+ attrs_to_remove.append(attr.name)
+
+ for a in attrs_to_remove:
+ if child.hasAttribute(a):
+ child.removeAttribute(a)
+
# check all substitutions to see if we found anything
# appropriate
frag.appendChild(child)
for instance in obj:
- newnode = frag.cloneNode(True)
- node.appendChild(newnode)
- process(newnode, instance, clean)
- if clean:
- _clean(newnode)
+ if instance is not None:
+ newnode = frag.cloneNode(True)
+ node.appendChild(newnode)
+ process(newnode, instance, clean)
+ if clean:
+ _clean(newnode)
# remove all the <fragment> tags
_clean(node)
def alternate(tag, array, *elems):
+ i = 0
+ for ref in array:
+ if ref is not None:
+ ref[tag] = elems[i % len(elems)]
+ i = i + 1
+
return array
def _clean(node):