Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
 
Old October 24th, 2008, 09:34 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default test if current-grouping-key() has changed?

Hi,

Is it possible to detect if the value of current-grouping-key() has changed in a for-each-group instruction. For example:

Code:
<xsl:for-each-group select="doc($geis)//number" group-by=".">
    <xsl:sort select="current-grouping-key()" order="ascending"/>
    <xsl:if test="????"> 
        <a name="{substring(current-grouping-key(), 1, 1)}"/>
    </xsl:if>
......
Thanks for the help.

Bones

 
Old October 24th, 2008, 09:48 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

xsl:for-each-group evaluates the body of the instruction once for each distinct value of the grouping key. So current-grouping-key() will always be different from the previous iteration, by definition.

Perhaps you should explain what you are trying to achieve.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 24th, 2008, 10:04 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Thank you Michael,

I am grouping part numbers in alpha-numeric order for html output. As I iterate through the for-each-group, I print out the current-grouping-key(). But I need to drop an anchor in for the index.
e.g.

Code:
<a name="{substring(current-grouping-key(), 1, 1)}"/>
I only want to do this once there is a change in the current-group()..
eg. A, B, C....

Thanks for the help.


 
Old October 24th, 2008, 10:22 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sounds like you need two levels of grouping: group first on the initial letter of the key, then on the full key.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 24th, 2008, 10:35 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

That's the trick.

Thanks!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Value of parent element of current-grouping-key() bonekrusher XSLT 2 September 9th, 2007 06:29 AM
Protect cells and allow grouping/un-grouping sfreuden Excel VBA 4 December 14th, 2006 08:01 AM
KEY - GROUPING pallone XSLT 9 December 11th, 2006 06:19 AM
Primary key changed - How to migrat database.? nmmure Crystal Reports 0 June 26th, 2006 03:47 PM
How to test for primary key exception? alexshiell Pro VB.NET 2002/2003 5 October 21st, 2004 07:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.