• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XSL distinct count problem...

 
Ranch Hand
Posts: 624
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I've read a few articles on Muenchian methods which dont seem to help me - but am still no closer to solving my problem (which I'm sure is solvable!)

I have a block of XML which I am processing with an XSL stylesheet to porduce HTML... My problems (aside from the compelte lack of decent tooling out there ) come when I want do some totalling.

My XML data contains timesheet data for a list of employees and I want to be able to display how many days the employee has worked. Problem is they may have several timesheet records for each day - so I need to do some groovy grouping before I do my count...

heres a sample bit of XML:



I'm doing the following in my xsl - but the count is NOT distinct (i.e. on the above data it counts 2 days when clearly both days are are the same!)..


<xsl:for-each select="Employee">
...
<xsl:value-of select="count(PayTypes/PayType/Days/Day[not(DayName = preceding-sibling:ay/DayName)]) "/>
...
</xsl:if>

Can anyone point me in the right direction?


-----------------------------------------------------------------------
Edit Comment: Disabled smiles.
[ October 18, 2004: Message edited by: Madhav Lakkapragada ]
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm doing the following in my xsl - but the count is NOT distinct (i.e. on the above data it counts 2 days when clearly both days are are the same!)..


In the count function above, you are counting the number of Day elements. It is not looking into the content of the element.

I am not clear on what exactly do you want to do ?
If you could clarify please.
Thanks.
 
Alan Wanwierd
Ranch Hand
Posts: 624
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks - but I actually got there myself. What I needed was:

<xsl:value-of select="count(PayTypes/PayType/Days/Day[not(DayName = ../../preceding-sibling::payType/Days/Day/DayName)]) "/>

complicated and ugly - but it works!

it counts the number of distinct days the current employee worked..
thanks for looking anyway!


-------------------------------------
Edit Comment: Disabled smiles.
[ October 18, 2004: Message edited by: Madhav Lakkapragada ]
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But why you don't want to use Date to distinguish days? What if somebody was sick, say, from one Wednesday to another?
 
Alan Wanwierd
Ranch Hand
Posts: 624
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mapraputa Is:
But why you don't want to use Date to distinguish days? What if somebody was sick, say, from one Wednesday to another?



ahh - yes good point - but actually the XML only ever has 1 weeks worth of data so its not an issue! (probably worth changing the code anyway just for future safety!)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic