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

Re:Grouping by element

Subject: Re:Grouping by element
From: "Yang" <sfyang@xxxxxxxxxxxxx>
Date: Fri, 7 Sep 2001 12:49:25 +0800
xml grouping by element
Hi, David,

>I trying to group nodes depending on any of the values it contains.

The xsl shown below hopefully is useful to you.  Basically it uses
key element to index Project node  for the first problem, and
the language node for the second one ( you can  index
Project node too).

***XSl  for problem 1 **
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="language" match="Project" use="language"/>
<xsl:variable name="language-id"
select="/Projects/Project[generate-id(.)=generate-id(key('language',
language)[1])]"/>
<xsl:template match="/">
<Projects>
<xsl:for-each select="$language-id">
<xsl:variable name="language" select="language"/>
<language id="{$language}">
 <xsl:apply-templates select="key('language',$language)"/>
</language>
</xsl:for-each>
</Projects>
</xsl:template>
<xsl:template match="Project">
<Project><xsl:copy-of select="name"/> </Project>
</xsl:template>
</xsl:stylesheet>


** xsl for problem 2  ***
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="language" match="language" use="."/>
<xsl:variable name="language-id"
select="/Projects/Project/language[generate-id(.)=generate-id(key('language'
, .)[1])]"/>
<xsl:template match="/">
<Projects>
<xsl:for-each select="$language-id">
<language><xsl:value-of select="."/> </language>
</xsl:for-each>
</Projects>
</xsl:template>
</xsl:stylesheet>

cheers,

Sun-fu Yang

sfyang@xxxxxxxxxxxxx



 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.