|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Grouping & use of keys
> I am a newbie at XSLT, have only written 1 identity transform > that took me 2 weeks to get working. I have a grouping task > for some xml data Grouping is MUCH easier in XSLT 2.0. Do you have anything that constrains you to XSLT 1.0? > > I think of <xsl:key......> as a declaration, similar to "new" > in some OO languages. Think of xsl:key as "create index", so <xsl:key name="es" match="employee" use="surname"/> creates an index of employees by surname, and key('es', 'Smith') finds the employees with surname 'Smith' In XSLT 2.0, to group employees by surname, you simply do <xsl:for-each-group select="employee" group-by="surname"> then <xsl:for-each select="current-group()"> In XSLT 1.0 you use Muenchian grouping, which logically does this: for each employee get the surname call key() to find all the employees with that surname apply [1] to get the first of these employees test whether this one is the current employee if so, treat this employee as the "owner" of the group find all employees with this surname by calling key() again and process them as required OK? Michael Kay http://www.saxonica.com/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






