Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 September 2nd, 2011, 04:26 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default using current-grouping-key in a select statement

Hi,

I am using Saxon from OxygenXML 13.

I am looking for tables in a rather large document and I want to copy those tables to the result.

what I have is:
Code:
<xsl:for-each-group select="$repoSubTree//table[@tabType='TL1Attribute']//entry/TL1Domain/DomRedir" group-by="./XRef/@Idref">
                <xsl:comment>
                    <xsl:text>Referenced Table: </xsl:text>
                    <xsl:value-of select="current-grouping-key()"></xsl:value-of>
                </xsl:comment>
                <xsl:text>&#x0a;</xsl:text>
                <xsl:apply-templates select="$repoSubTree//table[./title/@Id='{current-grouping-key()}']" mode="buildAux"></xsl:apply-templates>
            </xsl:for-each-group>
What I'm doing in the for-each-group is going through the document and finding every place a table is referenced, and using it's Idref to find the target table. I want to copy this table to the result.

In the result, the comments: "Referenced Table: " does show the correct set of IDs, so I'm pretty sure I got that part of the logic correct.

If I substitute one of the IDs in place of the {current-grouping-key()} in the last apply-templates, I do in fact get the table copied to the result. So I'm pretty sure that other template is also working.

What I thought would happen in this is that the ID would be substituted into the @Id='{current-grouping-key()}' for me in the for-each-group logic.

current-grouping-key() is giving me what I want, but apparently I'm not feeding it to the next template correctly.

Does anyone see what I missed?

Thanks,

- m
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare

Last edited by mphare; September 2nd, 2011 at 04:28 PM..
 
Old September 2nd, 2011, 04:40 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Never use curly braces within an XPath expression - they are only used to separate the XPath expression from surrounding literal text. Change

[./title/@Id='{current-grouping-key()}']

to

[./title/@Id=current-grouping-key()]

(The leading ./ is also redundant, though some people think it adds clarity)
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
mphare (September 2nd, 2011)
 
Old September 2nd, 2011, 04:55 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Also, if you document is large then you might consider using a <xsl:key> to speed up the lookups.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old September 2nd, 2011, 05:07 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

I wish I could find a nice emot-i-con for 'egg-on-face'

I tried exactly what you indicated and I thought it didn't work. Turns out it was because I had another typo that I didn't catch.

Works like a champ!

Thanks and have a great weekend!
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare





Similar Threads
Thread Thread Starter Forum Replies Last Post
test if current-grouping-key() has changed? bonekrusher XSLT 4 October 24th, 2008 10:35 AM
Value of parent element of current-grouping-key() bonekrusher XSLT 2 September 9th, 2007 06:29 AM
Select from another select statement to a repeater simsen ASP.NET 2.0 Professional 0 May 2nd, 2007 04:34 PM
KEY - GROUPING pallone XSLT 9 December 11th, 2006 06:19 AM
Select records not equal to current date SoC Classic ASP Basics 2 July 12th, 2005 10:20 PM





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