Hi, Jamie Norrish wrote:
I have a situation where I want to find any attributes in a document that contain a certain value, and then change that value and record the fact that the new value is the result of such a change. In order to track these changes, I am populating a dictionary keyed by the parent element, with each value being another dictionary keyed by attribute name with a value of the list of parts of the attribute that have been changed. So:
get_attrs = etree.XPath('//@*[contains(concat(" ", ., " "), concat(" #", $old_id, " "))]')
for attribute in get_attrs(element, old_id=some_string): element = attribute.getparent()
And then I discover that in fact I have to use element.attrib.items() and search through for which attribute matched. It would be much easier if the attribute 'smart' string result from the XPath evaluation had a method which would specify *which* attribute of the parent it was the value of.
I like that. It would be an attribute, though, maybe "attrname", to make it clear that the name is a) fixed at the time it's found and b) only available for attributes, as elements have their own way of providing the tag name (which is not fixed). Stefan