Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

XSL distinct values

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will look into into and get back.....interesting problem!

- m
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Madhav,
Thanx a lot that worked like a charm.
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic