Fix optimization when looking for attributes with any name ('*').
authorFrederic Jolliton <frederic@jolliton.com>
Wed, 7 Sep 2005 13:52:06 +0000 (13:52 +0000)
committerFrederic Jolliton <frederic@jolliton.com>
Wed, 7 Sep 2005 13:52:06 +0000 (13:52 +0000)
 * Fixed extDescendantAttribute function to handle correctly attribute
   name '*'.
git-archimport-id: frederic@jolliton.com--2005-main/tx--main--0.1--patch-1

xpathfn.py

index 2db805f..5c8c308 100644 (file)
@@ -287,11 +287,21 @@ def extDescendantAttribute( context , arg ) :
        name = arg[ 0 ]
        item = context.item
        if isDocument( item ) :
-               return Sequence( item.attributesByName.get( name , () ) )
+               if name == '*' :
+                       attrs = sum( item.attributesByName.values() , [] )
+                       attrs.sort( lambda a , b : cmp( a.position , b.position ) )
+                       return Sequence( attrs )
+               else :
+                       return Sequence( item.attributesByName.get( name , () ) )
        else :
-               return Sequence( attribute
-                                                for attribute in iterDescendantOrSelfFull( item )
-                                                if isAttribute( attribute ) and attribute.name == name )
+               if name == '*' :
+                       return Sequence( attribute
+                                                        for attribute in iterDescendantOrSelfFull( item )
+                                                        if isAttribute( attribute ) )
+               else :
+                       return Sequence( attribute
+                                                        for attribute in iterDescendantOrSelfFull( item )
+                                                        if isAttribute( attribute ) and attribute.name == name )
 
 #--[ XPath/XQuery functions ]------------------------------------------------