Refactor selecting values from an attribute

Move the code to select particular keys/indices from an attribute value out
of the get_attr intrinsic functions and into the attributes module as a
separate function.

Change-Id: I16135159027cc52e8da74a4b5863fc8a8595d582
Merge "Refactor selecting values from an attribute"