M
Michiel Kamermans
Hi,
I need to generate a list based on a sorted nodeset, except duplicates
need to be discarded. I initially though of doing a sort on a nodeset and
then passing it to a template that iterates over the set and compares the
current element it's processing to the previous one, continueing to the
next element immediately if it was the same as the previous one.
However, quite annoyingly the xsl:sort command cannot "just" be called, I
need to call it in a for-each, which seems to destroy the ability to
determine what the previous element processed was.
My idea was to do the following (in prologlike code)
buildlist() :-
node('//entry',List),
sort(List,SortedList)
writelist(Sortedlist,'',1).
writelist(List, Lastseen, Count) :-
Newcounter is Count + 1,
Element = List[Count],
( Lastseen != Element,
writeelement(Element)
;
# do nothing )
writelist(List,Element,Newcount).
writeelement(E) :- # do whatever writing is required here
I am not entirely sure why sort() never became a select function in
addition (or frankly, replacement) to being an element that can only be
used inside iteration, but it would seem that the fact that one cannot do
something like:
<xsl:variable name="sortedvarname" select="sort(variable,condition-
string)"/>
was a bad idea - but this is a problem I have with XSLT's design, so that
won't get me any closer to an answer =)
Does anyone know how to either obtain the count for which element from a
set is used in a foreach, or how to sort a nodeset before sending it on
for further processing in another template?
Mike Kamermans
I need to generate a list based on a sorted nodeset, except duplicates
need to be discarded. I initially though of doing a sort on a nodeset and
then passing it to a template that iterates over the set and compares the
current element it's processing to the previous one, continueing to the
next element immediately if it was the same as the previous one.
However, quite annoyingly the xsl:sort command cannot "just" be called, I
need to call it in a for-each, which seems to destroy the ability to
determine what the previous element processed was.
My idea was to do the following (in prologlike code)
buildlist() :-
node('//entry',List),
sort(List,SortedList)
writelist(Sortedlist,'',1).
writelist(List, Lastseen, Count) :-
Newcounter is Count + 1,
Element = List[Count],
( Lastseen != Element,
writeelement(Element)
;
# do nothing )
writelist(List,Element,Newcount).
writeelement(E) :- # do whatever writing is required here
I am not entirely sure why sort() never became a select function in
addition (or frankly, replacement) to being an element that can only be
used inside iteration, but it would seem that the fact that one cannot do
something like:
<xsl:variable name="sortedvarname" select="sort(variable,condition-
string)"/>
was a bad idea - but this is a problem I have with XSLT's design, so that
won't get me any closer to an answer =)
Does anyone know how to either obtain the count for which element from a
set is used in a foreach, or how to sort a nodeset before sending it on
for further processing in another template?
Mike Kamermans