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

RE: RE: RE: How to implement an array

Subject: RE: RE: RE: How to implement an array
From: cknell@xxxxxxxxxx
Date: Wed, 12 Feb 2003 14:18:49 -0500
union array
> Charles, thanks for your input on this as well. Since
> the solution originally came from you, I should have
> directed this question to you. Sorry for not following
> the messages in order.
> 
> Can you explain the use of the above select statement?
> Is 'union' a key word? And can you interchange it with
> the symbol '|'?
> 
> Imrran

<xsl:key name="union" match="group/table/col" use="@month" />

'union' is simply a string. It is the value of the "name" attribute of the <xsl:key> element. It could have been anything, and reflecting on you question, I suppose I should have used some name that wouldn't suggest a key word. <xsl:key> creates a kind of index.

As for this:
<xsl:for-each select="table/col[count(.|key('union', @month)[1])=
1]">

the select attribute tells the processor to take all the "col" elements which are children of "table" elements, which, in turn, are child elements of the context node (in this case, the context node is "group") and return the count of the union (which is represented by the vertical bar, or pipe character) of the context node (here the context is switched to "col") and the nodeset returned by the key() function.

The key() uses the index created by <xsl:key> to return a nodeset. The function takes two arguments, first is the value of the name attribute of the <xsl:key> element you want to work with, the second is the value you are looking for. Here the @month[1] is the value of the first occurrence of a month attribute value. Thus this returns all of the months, but only one of each.

So the <xsl:for-each> will iterate twelve times in this case. Each time we pull out the value of the month with <td><xsl:value-of select="@month" /></td>, and that gives us the column heads of the table.

All of this is explained in greater detail, and given the context and the author, with pains taking attention to accuracy, in Michael Kay's XSLT Programmer's Reference, 2nd Ed. from Wrox Books ISBN 1-861005-06-7.

-- 
Charles Knell
cknell@xxxxxxxxxx - email


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.