in reply to Sort xml based on attribute

I often use XML::XSH2. Leaving perl aside, the XSH code would look like this:
open 823927.xml ; register-namespace ani http://www.elsevier.com/xml/ani/ani ; for &{ sort :n /ani:bibdataset/ani:item/ani:bibrecord/ani:item-info/an +i:itemidlist/ani:itemid[@idtype="PUI"] } ls ancestor::ani:item