Subject: Re: [xsl] Extract unique list of attributes ... From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx> Date: Fri, 22 Jul 2005 23:11:41 +0530 |
This is the Muenchian grouping solution. <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" /> <xsl:key name="by-grade" match="student" use="@grade" /> <xsl:template match="/root"> <root> <grades> <xsl:for-each select="students/student[generate-id() = generate-id(key('by-grade', @grade)[1])]"> <grade level="{@grade}" /> </xsl:for-each> </grades> <xsl:copy-of select="students" /> </root> </xsl:template> </xsl:stylesheet> As Mike has said, you can also use distinct-values() function with a XSLT 2.0 stylesheet. Regards, Mukul On 7/22/05, Raghupathy S <raghupathy.s@xxxxxxxxx> wrote: > Hi, > > I'm a total newbie to XML / XSl, and I've been stuck with this problem. > Would be grateful for any suggestions / pointers > > The problem - > Assuming I have an xml file > > <root> > <students> > <student grade="first">abc</student> > <student grade="first">def</student> > <student grade="second">ghi</student> > <student grade="third">jkl</student> > <student grade="third">mno</student> > </students> > </root> > > I need to transform this into the following xml using an XSL > > <root> > <grades> > <grade level="first"/> > <grade level="second"/> > <grade level="third"/> > </grades> > <students> > <student grade="first">abc</student> > <student grade="first">def</student> > <student grade="second">ghi</student> > <student grade="third">jkl</student> > <student grade="third">mno</student> > </students> > </root> > > > I apologize if this is a totally newbie question, but ive been at my > wits end all day, trying to get this working. > > Any advice / help would be most appreciated. > > Thanks, > Rags
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Extract unique list of at, Michael Kay | Thread | [xsl] Special letters in XML - lis, Karl Koch |
RE: [xsl] Extract unique list of at, Michael Kay | Date | [xsl] Special letters in XML - lis, Karl Koch |
Month |