| Author |
XSL distinct values
|
Bhupendra Mehta
Greenhorn
Joined: Oct 29, 2004
Posts: 11
|
|
I have an xml of the form <data> <row> <col>2003-05-04</col> </row> <row> <col>2003-05-07</col> </row> <row> <col>2003-05-04</col> </row> <row> <col>2003-05-08</col> </row> <row> <col>2004-06-08</col> </row> <row> <col>2004-07-08</col> </row> . . . </data> The col element has dates in the form of yyyy-mm-dd. I am trying to find distinct yyyy-mm values from the above XML in a "variable". I can get distinct date values by using <xsl:variable name="distinctdate" select="//row[not(col[1]=preceding-sibling::row/col[1])]/col[1]"></xsl:variable> which gives me 2003-05-04 2003-05-07 2003-05-08 2004-06-08 2004-07-08 but what i'd really like is 2003-05 2004-06 2004-07 Any reponses will be greatly appreciated. Thanx
|
 |
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
|
|
<xsl:variable name="distinctdate" select="//row[not(col[1]=preceding-sibling::row/col[1])]/col[1]"></xsl:variable> Fudge this rule with the substring function: substring(col[1], 0, 7) so that you are comparing the first seven chars and not the value of the col element in its entirety. You will have to do some trial and error. I am leaving the homework for you. - m
|
 |
Bhupendra Mehta
Greenhorn
Joined: Oct 29, 2004
Posts: 11
|
|
Madhav, Thanx for the suggestion but i can't get the substring'd value. This is what I changed the rule to <xsl:variable name="distinctdate" select="//row[not(substring(col[1],1,7)=substring(preceding-sibling::row/col[1],1,7))]/col[1]"></xsl:variable> but I can't substring the final value that I'm retrieving //row[condition]/col[1] Thanx again.
|
 |
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
|
|
Will look into into and get back.....interesting problem! - m
|
 |
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
|
|
ok, I went ahead and modified one of my older style sheets for this - Kinda lengthy. Maybe there's a better way of doing this but once I started modifying my existing style sheet, I never looked back. So this probably is one way to do it, may not be the best. Sorry about being slack with the variable names and with the indenting. - m [ November 01, 2004: Message edited by: Madhav Lakkapragada ]
|
 |
Bhupendra Mehta
Greenhorn
Joined: Oct 29, 2004
Posts: 11
|
|
Madhav, Thanx a lot that worked like a charm.
|
 |
 |
|
|
subject: XSL distinct values
|
|
|