﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
572	QualifiedNameTest sets output attributes to `None`	Olemis Lang <olemis+trac@…>	hodgestar	"Consider the following script

{{{
#!py

'''
Created on Jul 9, 2013

@author: olemis
'''

from pprint import pprint

from genshi.template.markup import MarkupTemplate

if __name__ == '__main__':
    template_source = """"""<?xml version=""1.0"" encoding=""utf-8""?>
    <element xmlns:nspc1=""http://foo.org""
        nspc1:attribute=""value"">
    </element>
    """"""

    data = {}

    # XML stream
    template = MarkupTemplate(template_source)
    stream = template.generate(**data)

    for ev in stream.select('./@nspc1:attribute', {'nspc1' : 'http://foo.org'}):
        pprint(ev)

}}}

By executing it it's possible to notice how ''XPath'' expressions will
always evaluate to `None` when matching qualified attribute names.

{{{
#!sh
$ ./test_select1.py
Attrs([('attribute', None)])
}}}

After modifying `QualifiedNameTest.__call__` like shown below ...

{{{
#!py

    def __call__(self, kind, data, pos, namespaces, variables):
        qname = QName('%s}%s' % (namespaces.get(self.prefix), self.name))
        if kind is START:
            if self.principal_type is ATTRIBUTE and qname in data[1]:
                return Attrs([(self.name, data[1].get(qname))])
            else:
                return data[0] == qname
}}}

... the result looks better

{{{
#!sh
$ ./test_select1.py
Attrs([('attribute', u'value')])
}}}

Moreover this version will preserve namespace information

{{{
#!py

    def __call__(self, kind, data, pos, namespaces, variables):
        qname = QName('%s}%s' % (namespaces.get(self.prefix), self.name))
        if kind is START:
            if self.principal_type is ATTRIBUTE and qname in data[1]:
                return Attrs([(self.name, data[1].get(qname))])
            else:
                return data[0] == qname
}}}

Results

{{{
#!sh
$ ./test_select1.py
Attrs([(QName('http://foo.org}attribute'), u'value')])
}}}

IMO the last one is the most accurate considering that this may be
used to insert attributes in elements (e.g. `py:attrs=""select('@*')""`
in [wiki:GenshiTutorial#AddingaLayoutTemplate Genshi tutorial]).

BTW , I set version=develop in the ticket because this issue was
detected using both ''0.7'' and ''0.6'', and there's no option to
select the former.

priority=blocker because IMO this ticket only is a good reason to release 0.7.1"	defect	closed	blocker	0.7	XPath support	devel	fixed	qualified attribute name, XPath attribute axis	jcasado81@…
