def select_attribute(source, name, val=None):
def check(x):<EOL><INDENT>if val is None:<EOL><INDENT>return name in x.xml_attributes<EOL><DEDENT>else:<EOL><INDENT>return name in x.xml_attributes and x.xml_attributes[name] == val<EOL><DEDENT><DEDENT>return filter(check, select_elements(source))<EOL>
Yields elements from the source having the given attrivute, optionally with the given attribute value
source - if an element, starts with all child elements in order; can also be any other iterator
name - attribute name to check
val - if None check only for the existence of the attribute, otherwise compare the given value as well