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 June 19th, 2006, 08:20 AM
Registered User
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting distinct sibling values from a key

Hi,

what I am trying to do is to display unique records. I have written a key (level 1) using the Muenchian method which works OK. What I need to do next is to get the unique occurrances of the next level (y)from the group-by-x key (on the x node) that I have created.

So for the records which have x=14 I want the return to give 15 and 19 and not 15(twice) and 19 and to give a count of the unique occurances.

I have the following XML:

<z:row x 14 y 15 z 22/>
<z:row x 14 y 15 z 22/>
<z:row x 14 y 19 z 22/>
<z:row x 18 y 15 z 22/>
<z:row x 18 y 10 z 22/>

I have written the following XSL to try and group the records:

<xsl:output method="html"/>

<xsl:key name="group-by-x" match="/xml/rs:data/z:row" use="@x"/>

 <xsl:template match="/">
 <xsl:for-each select="z:row[generate-id(.)= generate-id(key('group-by-x',@x))]/@x">
       <xsl:value-of select="."/>

<xsl:call-template name="firstlevel">
<xsl:with-param name="xcode" select="." />
</xsl:call-template>
</xsl:for-each>
</xsl:template>

 <xsl:template name="firstlevel">
  <xsl:param name="xcode" />
    <xsl:value-of select="concat('', @x,' - There are ',count(key('group-by-x', $xcode)),' records:')"/><br/>

 </xsl:template>
</xsl:stylesheet>

This does what I want for the first level. The next stage is to display what each unique occuraances of 'y' there are in terms of x and then what occurances of z there in terms of x and y together. I have tried using the following:
select="key('group-by-x', .)/following-sibling::y"> but this doesnt work because of the way that my XML is structured.

Can anyone please advise as to how I could get round this problem?

Thanks in advance,
Chris
 
Old June 19th, 2006, 02:56 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

you could use another key, eg: something like
<xsl:key name="group-by-x-y" match="/xml/rs:data/z:row" use="concat(concat(@x, '-'), @y)"/>

Otherwise you'd probably have to use the preceding-sibling:: axis.

 
Old June 19th, 2006, 05:03 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I think there is some discussion of techniques for multi-level grouping at http://www.jenitennison.com/xslt/grouping

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
getting distinct values from attribute markus2000 XSLT 1 June 13th, 2006 03:06 AM
distinct-values in Javascript Jan1 XML 2 October 10th, 2005 04:56 AM
Distinct values of data arnabghosh Access 18 September 13th, 2005 05:41 PM
DISTINCT ntext Values fleming SQL Server 2000 2 July 23rd, 2005 06:58 PM
Accessing values from the last sibling node graywoodhouse XSLT 3 October 29th, 2004 06:15 AM





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