Hi !

I'm trying to create this issue against Genshi issue tracker

=========

Type: defect            Priority:        blocker
Milestone: 0.7          Component: XPath support        
Version: devel          Keywords: xpath, qualified names, attribute axis

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

=========

I always receive «Submission rejected as potential spam» , so I give up .

-- 
Regards,

Olemis.

Apache™ Bloodhound contributor
http://issues.apache.org/bloodhound

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

-- 
You received this message because you are subscribed to the Google Groups "Trac 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/trac-dev.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to