# HG changeset patch # User paulb # Date 1126305229 0 # Node ID f3ad418c58889325f650379361504a3891799de7 # Parent 1ba085b21c83c07a0f55d1f0f69cf1efcd6e81fb [project @ 2005-09-09 22:33:49 by paulb] Improved value copying and added retention of selected list items. diff -r 1ba085b21c83 -r f3ad418c5888 examples/Common/Dictionary/__init__.py --- a/examples/Common/Dictionary/__init__.py Fri Sep 09 22:33:03 2005 +0000 +++ b/examples/Common/Dictionary/__init__.py Fri Sep 09 22:33:49 2005 +0000 @@ -62,7 +62,9 @@ # Ensure all matches elements have at least one choice. # Copy selected matches to their corresponding text field. - for entry in words.xpath("words/entry"): + all_entries = words.xpath("words/entry") + + for entry in all_entries: matches_list = entry.xpath("matches") if len(matches_list) == 0: matches = words.createElement("matches") @@ -75,17 +77,12 @@ match_enum.setAttribute("word", "") matches.appendChild(match_enum) - if matches.hasAttribute("word"): - word = matches.getAttribute("word") - if word != "": - entry.setAttribute("word", word) - # Find requested search locations. if selectors.has_key("search"): entries = selectors["search"] elif in_page_resource == "matches": - entries = words.xpath("words/entry") + entries = all_entries else: entries = [] @@ -100,6 +97,18 @@ match_enum.setAttribute("word", found_word) matches.appendChild(match_enum) + # Copy selected values into text fields. + # NOTE: Since libxml2dom does not guarantee node equality for two nodes + # NOTE: referring to the same thing, we cannot just loop over all the + # NOTE: entries and query whether they reside in the search locations. + + for entry in all_entries: + matches = entry.xpath("matches")[0] + if matches.hasAttribute("word"): + word = matches.getAttribute("word") + if word != "" and word.startswith(entry.getAttribute("word")): + entry.setAttribute("word", word) + # Start the response. trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding))