def clean_attr(attr):
    """Append @ to attributes and resolve text -> text() for XPath."""
    if attr:
        if 'text' in attr:
            return 'text()'
        else:
            attr = attr.lstrip('@')
    if attr:
        return '@' + attr
    return None