]> granicus.if.org Git - python/commitdiff
handle_labels(): Fix problem for document fragments containing more
authorFred Drake <fdrake@acm.org>
Tue, 19 Jan 1999 21:46:48 +0000 (21:46 +0000)
committerFred Drake <fdrake@acm.org>
Tue, 19 Jan 1999 21:46:48 +0000 (21:46 +0000)
than one "root" that prevented all the <label id=...> items
from being promoted to id attributes on the enclosing chapter/
section/... properly.

Doc/tools/sgmlconv/docfixer.py

index 2aa7284beb03d5aaa1be77bc66d436114b9f01ee..985195f293dd90b3fa50721314d801ed4603e406 100755 (executable)
@@ -165,18 +165,20 @@ def handle_appendix(doc):
 
 
 def handle_labels(doc):
-    labels = doc.getElementsByTagName("label")
-    for label in labels:
-        id = label.getAttribute("id")
-        if not id:
-            continue
-        parent = label.parentNode
-        if parent.tagName == "title":
-            parent.parentNode.setAttribute("id", id)
-        else:
-            parent.setAttribute("id", id)
-        # now, remove <label id="..."/> from parent:
-        parent.removeChild(label)
+    for node in doc.childNodes:
+        if node.nodeType == xml.dom.core.ELEMENT:
+            labels = node.getElementsByTagName("label")
+            for label in labels:
+                id = label.getAttribute("id")
+                if not id:
+                    continue
+                parent = label.parentNode
+                if parent.tagName == "title":
+                    parent.parentNode.setAttribute("id", id)
+                else:
+                    parent.setAttribute("id", id)
+                # now, remove <label id="..."/> from parent:
+                parent.removeChild(label)
 
 
 def fixup_trailing_whitespace(doc, wsmap):