• 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

date range in xsl

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have an xml file =>
----------------------------------
<?xml version="1.0"?>
<data>
<customer id=1>
<Name>Tom</Name>
<DOB>
<Day>1</Day>
<Month>12</Month
<Year>1977</Year>
</DOB>
</customer>
<customer id=2>
<Name>Dick</Name>
<DOB>
<Day>1</Day>
<Month>12</Month
<Year>1977</Year>
</DOB>
</customer>
<customer id=3>
<Name>Harry</Name>
<DOB>
<Day>2</Day>
<Month>12</Month
<Year>1977</Year>
</DOB>
</customer>
</data>
-----------------------------
How do i count the total number of customer who has the same DOB - birthday? using xsl
 
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
total number of customer who has one particular birthday, like, say, 12/2/1977 or any birthday? Does your birthday include year?
 
Ng Jeffrey
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
count customers group by birth date using xsl
-> without hardcoding of birth date in xsl
actually, i found a <xsl:for-each-group> but it is available in xpath 2.0. it is able to handle my request... using saxon7 but the problem is i can't do multiple nest <for-each-group> working ... so i thought there might alternatives in xpath1.0
pls advise.
 
Mapraputa Is
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
If I understood your goal right, you can use parameters. I set them in XSLT for illustrative purpose, but you can set them when you apply your stylesheet.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="Day">1</xsl:param>
<xsl:param name="Month" select="12"/>
<xsl:param name="Year" select="1977"/>
<xsl:template match="/">
<xsl:value-of select="count (//DOB[Day=$Day and Month=$Month and Year=$Year])"/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
But if your file is long enough, this may work slow. Maybe you could use key() function instead - it is said to be much more effective.
[ April 19, 2002: Message edited by: Mapraputa Is ]
 
Ng Jeffrey
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what you have done is set a particular day, month, year which i do not want to do...
<xsl aram name="Day">1</xsl aram>
<xsl aram name="Month" select="12"/>
<xsl aram name="Year" select="1977"/>
the xsl should not contain any hardcoded information instead it should calculate the number of customers with their DOB grouped by year,month,day respectively...
 
Ng Jeffrey
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what i tried to do using xpath2.0 engine saxon7
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl utput method="text" indent="yes" />
<xsl:variable name="newline">
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:template match="/">
<xsl:for-each-group select="/"
group-by="Year">
<xsl:text>Total count (by year) = </xsl:text>
<xsl:value-of select="count(//Year)"/>
<xsl:value-of select="$newline"/>
<!-- ########LOGIC IS WRONG HERE ##### -->
<xsl:for-each-group select="/"
group-by="Month">
<xsl:text>Total count (by Month) = </xsl:text>
<xsl:value-of select="count(//Month)"/>
<xsl:value-of select="$newline"/>
<xsl:for-each-group select="/"
group-by="Day">
<xsl:text>Total count (by Day) = </xsl:text>
<xsl:value-of select="count(//Day)"/>
<xsl:value-of select="$newline"/>
</xsl:for-each-group>
</xsl:for-each-group>
<!-- TILL HERE -->
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
calculating customers GROUP BY YEAR,MONTH,DAY - that's my objective. The above result returns 3 for all groups ...
or are there alternatives to handle such situations
pls advise
 
Mapraputa Is
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
Then everything is much worse XSLT isn't too well suited for grouping tasks. This looks close to what you need.
 
Ng Jeffrey
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the useful link ... it gives me an idea how i should counter my problem ...
 
reply
    Bookmark Topic Watch Topic
  • New Topic