A few years back, there was a post about using the Muenchian Method in a sorted for-each that seems relevant to my problem, but I don't see any responses [http://marc.info/?l=xalan-j-users&m=109705190806154&w=2]. Does anyone know the resolution for Simon's issue? In my case, I've got a stylesheet iterating over a distinct list formed from a Muenchian-style key. Each pass includes a nested for-each across the same key that includes a sort. In case1.xslt, the COUNT node using the same xpath as the for-each's select correctly shows that there are two CURRENCY_FLAG values, but the subsequent for-each iteration finds four. Note that four unique ID's are discovered. When I created a variable to hold the xpath's result (case2.xslt), both the COUNT and the number of iterations was correct. Can I infer that: a) Sorting a key's list is performed by reference in memory and can alter the list itself. This could affect nested sorts of keys. b) Creating a variable creates a copy of the list, such that subsequent modifications do not affect the "variable-ized" list. This is all using Xalan 2.7.1. Files are attached. Thanks, Alex
input.xml
Description: Binary data
case1.xslt
Description: Binary data
case2.xslt
Description: Binary data