Hi,I wanted to sort my items which contains many values. I use iw_iterate to display these values. Is there any default function available in to sort iw_iterate values or pls help me how to do the logic.Scenario:I have item called country and it can have any number of languages(nested container). The output is, i should print the country name(sorted) and list of languages by the side.AAmerica English1 English2 English 3IIndia Hindi1, Hindi2, Hindi3.Can somebody help me on deriving this output.SARA
{Country-1 => [language-1, language-2, ..., language-N],Country-2 => [language-1, language-2, ..., language-N], ...Country-N => [language-1, language-2, ..., language-N],}
my @countries = grep { $_->type() ne "CDATA" } sort( iwpt_dcr_list('xpath.to.countries.container'));foreach my $c (@countries) { ...}
my @languages = grep { $_->type() ne "CDATA" } sort ('c.languages.container'));foreach my $l (@languages) { ...}
http://your-server/iw/help/tst/pt/TeamSite__PT__iw_iterate.html
See: http://your-server/iw/help/tst/pt/TeamSite__PT__iw_iterate.html iw_iterate appears to have an order attribute.
I'm not sure I understand completely the data structure here - but it sounds like:{Country-1 => [language-1, language-2, ..., language-N],Country-2 => [language-1, language-2, ..., language-N], ...Country-N => [language-1, language-2, ..., language-N],}I've shown it above in terms of a Perl sructure (a hash in which each key is the name of a country and the values associated with each key is an array of languages [or references to such structures]) - If you're using the PT compiler system - this is the best way to think about it (IMO) since the PT compiler system is Perl-based.Sorting at each level should be pretty easy since it looks like a basic lexical sort: my @countries = grep { $_->type() ne "CDATA" } sort( iwpt_dcr_list('xpath.to.countries.container'));foreach my $c (@countries) { ...} Then you can traverse through each of those items, and dereference it to sort the contents of the languages associated with the country (if you actually want to do that? Are the languages to be lexically sorted, or weighted such that the order within the DCT is the order to be used?). If they are to be lexically sorted, code similar to the above could be used there too:my @languages = grep { $_->type() ne "CDATA" } sort ('c.languages.container'));foreach my $l (@languages) { ...}You can do the same thing with iwiterate - I just find it easier to think in terms of the underlying Perl constructs.There may be an additional dereference needed within each loop - but you can figure that out while coding / testing.
Hi Dazzald,I think the order is used to display the item values from top to bottom or bottom to top. That will not help for sorting.There is also a attribute called sort is used within iw_iterate, but am not able to understand the examples given. If you have any real time example. pls provide.Sara
Have you really looked at the URL that Dazzlad suggested? 'order' attribute allows you to specify a function that reorders the list.There is no 'sort' attribute. In Ghoti's sample sort is a Perl command. Note that Perl's sort allows to define your own comparison functionand this is exactly what 'order' attribute value should refer to. In other words, the presnce of 'order' tells TS: "iterate sorted, comparison function is so-and-so"
... order='( code-or-subroutine-reference )' ...
This is a useful article that describes sorting in Perl.http://www.perlfect.com/articles/sorting.shtmlShould be of help when writing your function.