xsl-list
[Top] [All Lists]

RE: How do you select all unique first-position characters?

2002-11-20 16:46:53
At 03:39 PM 11/20/2002, you wrote:
I'm not sure if this what your going for, but the template below can either
retrieve you a text list (see comments) or a nodelist containing the nodes
of the all unique first letters where the assumption is which person node it
is doesn't matter.

[snip]

The template you offered only works for the particular xml data given. Simply add the element <person name="Greg" /> between Jim and Jason and you will see that it breaks. You are using "preceding-sibling::*[1]" for the comparison, thinking that you are comparing the elements in a sorted order. What you do not realize (and I only just discovered this myself while examining your template) is that it does not take into account the new sorting when dealing with node selection. The axes appear to be strictly related to the original order (at this point in the template anyway), so the first preceding-sibling element of 'Jim' is always going to be 'Amy', never 'Jason' as you might think after alphabetizing. The sort order is simply the order in which the original elements are processed; it does not recreate the document tree to reorder the nodes. For the original example (and using a JavaScript-like pseudo code) it works more like this:

for index in (2, 3, 1, 5, 4)
  doSomethingWith(person[index]/@name);


Greg Faron
Integre Technical Publishing Co.



XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list