Subject: Re: [xsl] Variable containing unique values From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Wed, 21 May 2008 21:31:24 +0530 |
Following is a XSLT 1.0 solution to this problem based on Muenchian grouping technique: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text" /> <xsl:key name="x" match="rolloverDate" use="." /> <xsl:template match="/"> <xsl:for-each select="//rolloverDate[generate-id() = generate-id(key('x',.)[1])]"> <xsl:value-of select="." /><xsl:if test="position() != last()">,</xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> If you want to store the unique data list in a variable, you can do: <xsl:variable name="uniqueDates"> <xsl:for-each select="//rolloverDate[generate-id() = generate-id(key('x',.)[1])]"> <xsl:value-of select="." /><xsl:if test="position() != last()">,</xsl:if> </xsl:for-each> </xsl:variable> PS: The values in this example are comma separated. On Wed, May 21, 2008 at 7:29 PM, Hesselberth, Jan <Jan.Hesselberth@xxxxxxxxxxxxxxxxxx> wrote: > I've read the book and looked at the examples but I can't manage to > create a variable containing unique values for my xml. All I get is a > list of all values. > I need a variable containing unique values for rolloverDate. I've tried > all sorts of rules for testing for current rolloverDate not being equal > to previous rollover dates but I can't get it to work. > Can you help please. > Regards > Jan Hesselberth > > The code I have is > > <xsl:variable name="unique-dates"> > <xsl:for-each > select > ="REPORT/Rollover/RolloverForecast/summaryAccount/element"> > <xsl:sort > select="/rolloverDate[not(preceding::rolloverDate= current())]"/> > <xsl:copy-of select="."/> > </xsl:for-each> > </xsl:variable> > > The xml snippet looks like > > <summaryAccount id="12345"> > <isAutomatedRollover>N</isAutomatedRollover> > <element id="1"> > <rolloverDate>2008-04-04</rolloverDate> > </element> > <element id="2"> > <rolloverDate>2008-04-04</rolloverDate> > </element> > </summaryAccount> > <summaryAccount id="12346"> > <isAutomatedRollover>Y</isAutomatedRollover> > <element id="1"> > <rolloverDate>2008-04-22</rolloverDate> > </element> > </summaryAccount> > <summaryAccount id="12347"> > <isAutomatedRollover>Y</isAutomatedRollover> > <element id="1"> > <rolloverDate>2008-04-22</rolloverDate> > </element> > <element id="2"> > <rolloverDate>2008-04-17</rolloverDate> > </element> > </summaryAccount> -- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Variable containing uniqu, Hesselberth, Jan | Thread | RE: [xsl] Variable containing uniqu, Hesselberth, Jan |
RE: [xsl] Variable containing uniqu, Hesselberth, Jan | Date | RE: [xsl] Variable containing uniqu, Hesselberth, Jan |
Month |