I don't even know if this is possible, but I feel stuck, so any ideas or solutions are appreciated.
I have a property called 'MemberId' on some of my pages.
I now want to create a list over the MemberId's who have the most pages tagged with their ID, but I don't know where to start :) This is probably not doable with xslt.
The goal of the list is to look something like this.
[memberId] - [numberofpages]
This is all I have got so far :)
[code]
[/code]
This gives me a list sorted by MemberId, but somehow I want to group them and count the occurrences.
Iterate the sorted list, don't process if current member'id is equal to last record's member id and for each member id in the list that you do process, create some juicy xpath expression to get the number of occurences.
I'm sure this will work, not sure if this is the most elegant solution... but what is elegant in terms of xslt?
Hi fed, I tend to use id's and key's for this kind of grouping etc.
It's a bit weird getting the grips of in the beginning, but once you get it it's extremely powerful - and normally outperformances other iterative solutions.
* Define some special key/function used for grouping the nodes - in your case it's simply using the MemberId, but it could be more advanced. It's a bit similar to a hash-function. All nodes with the same key value defines a group.
* Find the first node of every group. This is done by comparing unique node-id's (fetched by generate-id() with the first node-id of the group). This is the outer for-each
* Iterate over all nodes in a group using the key() function for fetching all nodes with a specific value. The Key() function returns a node-set.
XSLT Group / Order / Count
I don't even know if this is possible, but I feel stuck, so any ideas or solutions are appreciated.
I have a property called 'MemberId' on some of my pages.
I now want to create a list over the MemberId's who have the most pages tagged with their ID, but I don't know where to start :) This is probably not doable with xslt.
The goal of the list is to look something like this.
[memberId] - [numberofpages]
This is all I have got so far :)
[code]
[/code]
This gives me a list sorted by MemberId, but somehow I want to group them and count the occurrences.
Any ideas are appreciated.
Hi fed,
Iterate the sorted list, don't process if current member'id is equal to last record's member id and for each member id in the list that you do process, create some juicy xpath expression to get the number of occurences.
I'm sure this will work, not sure if this is the most elegant solution... but what is elegant in terms of xslt?
Cheers,
/Dirk
Hi fed, I tend to use id's and key's for this kind of grouping etc.
It's a bit weird getting the grips of in the beginning, but once you get it it's extremely powerful - and normally outperformances other iterative solutions.
In your case it would be something like this:
[code]
()
[/code]
Hope this helped
Thanks a lot, worked like a charm.. Haven't gotten my head around how it works yet :) but atleast it works!
Thanks..
Basically it is:
* Define some special key/function used for grouping the nodes - in your case it's simply using the MemberId, but it could be more advanced. It's a bit similar to a hash-function. All nodes with the same key value defines a group.
* Find the first node of every group. This is done by comparing unique node-id's (fetched by generate-id() with the first node-id of the group). This is the outer for-each
* Iterate over all nodes in a group using the key() function for fetching all nodes with a specific value. The Key() function returns a node-set.
@tommyp: Great piece of xslt art! I have to bookmark this!
Cheers,
/Dirk
[quote=Dirk]@tommyp: Great piece of xslt art! I have to bookmark this!
Cheers,
/Dirk
[/quote]
Thanks Dirk, glad you liked it
You can find the original on my blackpoint.dk site.
is working on a reply...