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 January 19th, 2010, 08:14 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default Grouping by pattern

Hi,

I have xml table that has about 1000 rows (<tr>). I am trying to group the rows by a pattern found in the @id attribute.

Code:
<tr id="ctl00_ContentPlaceHolder1_PICList_gridPICList__1_2_1cat" >
The pattern is the 3 characters after "ctl00_ContentPlaceHolder1_PICList_gridPICList __", which is 1_2

I tried:

Code:
<xsl:for-each-group select="//tr" group-by="substring(@id, 47 , 3)">
which provides weird results.

XSLT:
Code:
<xsl:template match="/">
    <data>
        <xsl:for-each-group select="//tr" group-by="substring(@id, 47 , 3)">
            <xsl:comment>
                <xsl:value-of select="current-grouping-key()"/>
            </xsl:comment>
        </xsl:for-each-group>
    </data>
</xsl:template>
Outputs:

Code:
<data >
    <!---->
    <!--_1c-->
    <!--_1_-->
</data>
Any suggestions would be appreciated.

Thx
 
Old January 19th, 2010, 08:29 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well in your example it looks like the substring '1_2' actually starts at character 48 - this explains the '_1_' in your sample output.

As for the others - I'm guessing that not all rows have the same number of characters before what you are trying to split on. Is it possible you could split on something else, perhaps "__"? If so then try to tokenize() function.

<xsl:for-each-group select="//tr" group-by="substring(tokenize(., '__')[2],1,3)">
...
</xsl:for-each>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
bonekrusher (January 19th, 2010)
 
Old January 19th, 2010, 09:56 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Perfect. thx a lot.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Pattern extension? tdewey BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 1 May 13th, 2009 10:20 PM
I need help with pattern recognition jazokita Pro Java 2 February 8th, 2009 05:34 PM
Protect cells and allow grouping/un-grouping sfreuden Excel VBA 4 December 14th, 2006 08:01 AM
last directory pattern pc2006 BOOK: Beginning Regular Expressions 1 September 8th, 2006 12:45 AM
DirectoryInfo.GetFiles(pattern): search pattern fo arif_1947 VS.NET 2002/2003 1 October 19th, 2004 11:59 PM





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