1.1 --- a/examples/Common/Dictionary/__init__.py Fri Sep 09 22:33:03 2005 +0000
1.2 +++ b/examples/Common/Dictionary/__init__.py Fri Sep 09 22:33:49 2005 +0000
1.3 @@ -62,7 +62,9 @@
1.4 # Ensure all matches elements have at least one choice.
1.5 # Copy selected matches to their corresponding text field.
1.6
1.7 - for entry in words.xpath("words/entry"):
1.8 + all_entries = words.xpath("words/entry")
1.9 +
1.10 + for entry in all_entries:
1.11 matches_list = entry.xpath("matches")
1.12 if len(matches_list) == 0:
1.13 matches = words.createElement("matches")
1.14 @@ -75,17 +77,12 @@
1.15 match_enum.setAttribute("word", "")
1.16 matches.appendChild(match_enum)
1.17
1.18 - if matches.hasAttribute("word"):
1.19 - word = matches.getAttribute("word")
1.20 - if word != "":
1.21 - entry.setAttribute("word", word)
1.22 -
1.23 # Find requested search locations.
1.24
1.25 if selectors.has_key("search"):
1.26 entries = selectors["search"]
1.27 elif in_page_resource == "matches":
1.28 - entries = words.xpath("words/entry")
1.29 + entries = all_entries
1.30 else:
1.31 entries = []
1.32
1.33 @@ -100,6 +97,18 @@
1.34 match_enum.setAttribute("word", found_word)
1.35 matches.appendChild(match_enum)
1.36
1.37 + # Copy selected values into text fields.
1.38 + # NOTE: Since libxml2dom does not guarantee node equality for two nodes
1.39 + # NOTE: referring to the same thing, we cannot just loop over all the
1.40 + # NOTE: entries and query whether they reside in the search locations.
1.41 +
1.42 + for entry in all_entries:
1.43 + matches = entry.xpath("matches")[0]
1.44 + if matches.hasAttribute("word"):
1.45 + word = matches.getAttribute("word")
1.46 + if word != "" and word.startswith(entry.getAttribute("word")):
1.47 + entry.setAttribute("word", word)
1.48 +
1.49 # Start the response.
1.50
1.51 trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding))