[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:key grouping problem

Subject: Re: xsl:key grouping problem
From: Mark Ivs <markivs2003@xxxxxxxxx>
Date: Wed, 17 Nov 2004 13:06:18 -0800 (PST)
xsl key concat
Thank you for the detialed explanation. It was very
helpful. One last thing. I would like to display my
results in 2 or 3 table columns. The way it is right
now, it will only display one column. Please see xsl
below. Thanks again.

  <xsl:key name="groups" match="country"
use="concat(country_group, 
@year, @num)"/>

  <xsl:template match="myroot">
    <table>
    <xsl:for-each select="country[generate-id() =
generate-id(key('groups', concat(country_group,
'2004', '2')))]">
      <tr><td>
         <xsl:value-of select="country_group"/>
      </td></tr>
    </xsl:for-each>
    </table>
  </xsl:template>
  
Thanks again.
Mark


--- David Carlisle <davidc@xxxxxxxxx> wrote:

> 
> 
> > Using xsl keys seems like a tough concept to
> > understand(atleast for me). Are there other
> novices
> 
> keys themselves are simple enough, but using them
> (as here) for grouping
> isn't at all obvious and is normally called (here at
> least) Muenchian
> grouping after Steve Muench who first thought of
> this.
> Jeni's site is the usual reference for a tutorial.
> 
> http://www.jenitennison.com/xslt/grouping/index.html
> 
> >  How does generate-id on country be equal to
> >  generate-id on the key? That's where I am
> confused.
> >  country[generate-id() = generate-id(key('groups',
> >  concat(country_group, '2004', '2'))) ??
> 
> 
> The trick here is that if you are on a country then
> concat(country_group, '2004', '2')
> is the key string you want to use and so
> 
> key('groups', concat(country_group, '2004', '2'))
> 
> will return all the nodes that we want to consider
> to be grouped with
> this country.
> 
> Now the test is trying to say "is this node the
> first node in this
> group" (if so start processing the group, if not do
> nothing as this node
> was already handled when the rest of the group was
> handled, on the first
> node)
> 
> so this node is .
> 
> and the first node in the current group is
> 
> key('groups', concat(country_group, '2004', '2'))[1]
> 
> so you want to know if
> 
> . is key('groups', concat(country_group, '2004',
> '2'))[1]
> 
> now in XPath 2 (draft) there is an "is" operator
> that tests node
> identity and the above line is actually valid Xpath2
> but in Xpath 1
> there is no operator. You can't "is". You can't use
> use = as
> 
> 
> . = key('groups', concat(country_group, '2004',
> '2'))[1]
> 
> would test if the string value of the current node
> was equal to the
> string value of the first node in the group, which
> isn't what we want.
> 
> however generate-id returns a unique string for each
> node so you can say
> 
> generate-id(.) = generate-id(key('groups',
> concat(country_group, '2004', '2'))[1])
> 
> and that will be true just if the current node is
> the first node in the
> group.
> 
> This idiom isn't at all obvious but it is a FAQ and
> when you've seen it
> most days on this list for 5 years you tend to take
> some syntactic
> shortcuts:
> 
> generate-id(.)
> 
> can be written
> 
> generate-id() because . is implied if you supply no
> argument.
> 
> generate-id(key('groups', concat(country_group,
> '2004', '2'))[1])
> 
> can be written
> 
> generate-id(key('groups', concat(country_group,
> '2004', '2')))
> 
> because as for most string generating functions in
> XSLT 1, if you supply
> a node set as an argument it will take the first
> node in teh set in
> document order and use that and silently ignore any
> other nodes, in
> other words [1] is implictly applied.
> 
> David
> 
>
________________________________________________________________________
> This e-mail has been scanned for all viruses by
> Star. The
> service is powered by MessageLabs. For more
> information on a proactive
> anti-virus service working around the clock, around
> the globe, visit:
> http://www.star.net.uk
>
________________________________________________________________________
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.