This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: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@unisvr.net.tw



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]