 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 6th, 2006, 09:04 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Grouping and (dynamic) sorting
Hallo everyone,
I have an XSL stylesheet which consolidates (groups) data to display totals (e.g. for each team). I have found that on some fields I can add a sort ...
<xsl:apply-templates select="rep_base[generate-id()=generate-id(key('kteam', team)[(plt=$pfiltfld) and GR_CNT > 0])]" mode="dteam">
<xsl:sort select="team"/>
</xsl:apply-templates>
... works fine.
Indeed, I have even found that I can replace the sort clause with a parameter (the column name) and that also works fine:
<xsl:sort select="*[name()=$pcol]"/>
... which I was pleased about.
However, when a try to filter on columns which are key-generated (during the consolidation), the system executes but brings a chaotic (non-sorted) listing. The columns that are giving me problems are ones like the following:
<td><xsl:value-of select="key('krefteam', $pteamcodestore)[1]/TEAM_NAME" /></td>
... where TEAM_NAME is being selected (as the first item) from a reference section in the XML (i.e. list of all teams).
And from:
<td ALIGN="RIGHT"><xsl:value-of select="sum(key('kteam', team)[*[name()=$plevel]=$pfiltfld]/GR_CNT)" /></td>
... where GR_CNT is the result of a consolidation (on the key 'team')
So my question here is whether I am trying to ask too much of XSLT? Or if there is alternative syntax that I can use to get the sorting to work?
Any tips would be a great help as I often need to consolidate data (dynamically) and then sort that data (i.e. the user would like to see the biggest numbers at the top).
Regards and thanks,
Alan Searle
|
|

November 7th, 2006, 04:33 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi All,
I wanted to post a second note because this one is really turning into a headache for me ...
The data in my XSL displays fine (nice tabular format with various groups) but it is important that the users are able to sort the data as they require.
I have implemented a javascript process which allows the user to click on the column head to resort by that column. This works fine on the core data (e.g. on team which is the criteria for the grouping) but when I try to apply a sort to the summed / grouped column, then I can a 'chaotic' sort order.
So my problem is how to sort on grouped/summed columns?
Below is an excerpt from my syntax. Or maybe someone has a basic suggestion on the logic for sorting on grouped data?
Many thanks,
Alan Searle
-------------------------------------------------
Example:
<xsl:apply-templates select="rep_base[generate-id()=generate-id(key('kteam', team)
[PLANT=$pfiltfld])]" mode="dteam">
<xsl:sort select="GR_CNT"/>
</xsl:apply-templates>
excerpt from template ...
sum(key('kteam', team)[PLANT=$pfiltfld]/GR_CNT)
|
|

November 7th, 2006, 10:29 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
What exactly do you want to happen? If you have employees grouped by location, what do you want to see on the screen when you then sort them by age?
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

November 7th, 2006, 11:03 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have the following table ...
Dept Team TeamName GoodsReceived
M ABC SalesStreatham 34
M DEF SalesTooting 77
M HIJ SalesWimbledon 22
... where GoodsReceived (GR) is a summ of data for each team.
Here find that I can activate a dynamic sort on Team (that is the key field declared for the grouping) and that sort comes back correct.
However, when I try to sort on GoodsReceived (which is a summing based on the Team group), it works but I get a chaotic sort-order.
My assumption is that I must be misunderstanding something with the mechanism XSL uses to group.
Maybe I need to include details of the key reference in my 'sort clause'?
I really hope I can get this working because the users want to be able to compare data by sorting on various columns.
Thanks very much for your help.
Regards,
Alan.
PS: The funny thing is that I also get a chaotic sort when I try to sort on TeamName
|
|

November 7th, 2006, 11:20 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I think it might be a good idea if you showed me your code. If you're displaying one row for each group, then if you use the expression EXP for displaying a value then I would think you can also use the same expression EXP in your sort definition. For example, if you display
<xsl:value-of select="sum(key('k', team)/price)"
then you could also compute
<xsl:sort select="sum(key('k', team)/price)" data-type="number"/>
The only constraint, of course, is that the sort key (in 1.0) must be calculated using a single XPath expression - there's no scope for using intermediate variables, for example.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

November 10th, 2006, 03:36 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Michael,
Yes, that fixed the problem: I needed to include the full formula for the calculation of the underlying data.
And, yes, I have also noticed that using the key functionality for sorting and grouping means that it is often not possible to parameterize the grouping. That's a bit irritating because I would like to include more dynamic features. Will this be different with XSL 2.0? Indeed, XSL 2.0 seems to have a much more comfortable method of grouping.
The problem is that the company only has XSL 1.0 installed in their browsers. I would like to talk to the administrators to get XSL 2.0 installed but am a bit short of information. Is there a site where I can download XSL 2.0? Or maybe a 'White Paper' that I can pass on to the administrators of our IT systems? That would be a great help.
Regards and thanks,
Alan.
|
|

November 10th, 2006, 05:06 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
As far as I know there are no main stream browsers that support XSLT 2.0. If you wanted to harness it you'd have to use server-side transformation, Saxon is possibly the only current version 2.0 processor that can be easily integrated with Java and .NET. Of course this means that you don't get the responsiveness of client-side manipulation but that can be overcome to some extent with Ajax.
--
Joe ( Microsoft MVP - XML)
|
|

November 10th, 2006, 05:18 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Joe,
Thanks for confirming that.
I think it rules out XSL 2.0 for us at the moment because we are completely dependent on client-side processing.
Anyway, I hope that XSL 2.0 will soon be included in browsers. And I also hope that various browsers will fix some kind of 'standard' so that code can be written to run on all browsers.
Regards,
Alan.
|
|

November 10th, 2006, 05:23 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Quote:
quote:Originally posted by asearle
Anyway, I hope that XSL 2.0 will soon be included in browsers. And I also hope that various browsers will fix some kind of 'standard' so that code can be written to run on all browsers.
|
And I'd like world peace and end to poverty but there's about as much chance...
--
Joe ( Microsoft MVP - XML)
|
|

November 10th, 2006, 05:38 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry, Joe, I wasn't trying to reproach anyone ... I was just day-dreaming.
And, yes, world peace would be good too :-)
Cheers,
Alan.
|
|
 |