[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Selecting entries by date


Subject: Re: [xsl] Selecting entries by date
From: Mukul Gandhi <mukulw3@xxxxxxxxx>
Date: Sun, 3 Aug 2003 08:39:51 -0700 (PDT)

Hi Chuck ,
To perform date calculations i would prefer to use
standard based approach like using EXSLT.. Below is
the complete XSL. i have used date:difference function
to calculate date differences. The EXSLT difference
function accepts date in format CCYY-MM-DD, so i have
used the XSLT translate function to perform this
translation. i have tested with Xalan, and it produces
result in the desired format. i am sure it will work
with Saxon also. 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date">
  <xsl:import href="date.xsl"/>
  <xsl:output method="text" version="1.0"
encoding="UTF-8" indent="yes"/>
 <xsl:variable
name="thismonth">2003.07.01</xsl:variable>

 <xsl:template match="hlist">
   <xsl:for-each select="entry">
     <xsl:sort select="lastname"/>
       <xsl:variable name="date_of_entry"
select="translate(dateofentry, '.', '-')"/>
       <xsl:variable name="diff">
         <xsl:call-template name="date:difference">
	   <xsl:with-param name="start"
select="translate($thismonth, '.', '-')"/>
	   <xsl:with-param name="end"
select="$date_of_entry"/>
          </xsl:call-template>
	</xsl:variable>
    <!-- the 'if' below executes when dateofentry
field is after 'thismonth'-->
    <xsl:if test="not(starts-with($diff,'-'))">
       <xsl:value-of select="position()"/>
       <xsl:text>. </xsl:text>
       <xsl:value-of select="firstname"/>
       <xsl:text> </xsl:text>
       <xsl:value-of select="lastname"/>
       <xsl:text>, </xsl:text>
       <xsl:value-of select="affiliation"/>
       <xsl:text>.  Area: </xsl:text>
       <xsl:value-of select="area"/>
       <xsl:text>.  Topic(s): </xsl:text>
       <xsl:value-of select="topic"/>
       <xsl:text>&#xa;</xsl:text>
       <xsl:text>&#xa;</xsl:text>
     </xsl:if>
   </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

If you wish, the XSL may accept parameter for 'this
month' , as --
<xsl:param name="thismonth"/> (instead of hardcoding
within XSL). You can then supply 'thismonth' value
from command line without changing the XSL..


Hope it helps,

Regards,
Mukul


--- Charles Muller <acmuller@xxxxxxx> wrote:
> I administer an e-mail list, for which I maintain a
> subscriber list that
> includes their main research areas and topics. At
> the end of each month,
> I send out a list of new subscribers for that month,
> including research
> information, but not their e-mail addresses. Up to
> now, I had
> been selecting this month's new subscribers
> manually, but now I want to
> select them via XSLT using <xsl:if> with their
> <dateofentry> node. I am
> getting stuck. When I use the date form 2003.07.01
> the parser
> (Saxon, in Emacs) says its not a valid number. When
> I change the form to
> 20030701, the code below generates the entire list,
> regardless of date.
> 
> The format of the XSL entries is:
> 
> <hlist>
> <entry>
> <e-mail>johndoe@xxxxxxx</e-mail>
> <firstname>John</firstname>
> <lastname>Doe</lastname>
> <affiliation>This University</affiliation>
> <dateofentry>2003.08.03</dateofentry>
> <area>His Country</area>
> <topic>His favorite topics</topic>
> </entry>
> <entry>
> <e-mail>acmuller@xxxxxxxxx</e-mail>
> <firstname>Charles</firstname>
> <lastname>Muller</lastname>
> <affiliation>Toyo Gakuen University</affiliation>
> <dateofentry>1999.05.14</dateofentry>
> <area>Korea</area>
> <topic>Korean Seon; Woenhyo, Gihwa; East Asian
> Yogaacaara; Confucianism and Daoism</topic>
> </entry>
> <hlist>
> 
> The below style is intended to output John Doe, but
> not Charles Muller,
> but apparently has an error or two (I've left out
> prior code in the
> sheet that was already functioning correctly before
> I tried to add this
> date selector):
> 
>  <xsl:variable name="entrydate"
> select="hbuddhism/entry/dateofentry"/>
> <xsl:variable name="thismonth" select="2003.07.01"/>
>  <xsl:if test="$entrydate &gt; $thismonth">
>  <xsl:for-each select="hbuddhism/entry">
>    <xsl:sort select="lastname"/>
>    <xsl:value-of select="position()"/>
>    <xsl:text>. </xsl:text>
>    <xsl:value-of select="firstname"/>
>    <xsl:text> </xsl:text>
>    <xsl:value-of select="lastname"/>
>  <xsl:text>, </xsl:text>
>     <xsl:value-of select="affiliation"/>
>     <xsl:text>.  Area: </xsl:text>
>        <xsl:value-of select="area"/>
>         <xsl:text>.  Topic(s): </xsl:text>
>        <xsl:value-of select="topic"/>
>        <xsl:value-of select="$newline"/>
>        <xsl:value-of select="$newline"/>
>    </xsl:for-each>
>  </xsl:if>
> 
> 
> Thanks for looking at this.
> 
> Chuck
> 
> ---------------------------
> Charles Muller  <acmuller@xxxxxxx>
> Faculty of Humanities,  Toyo Gakuen University
> Digital Dictionary of Buddhism and CJKV-English
> Dictionary [http://www.acmuller.net]
> H-Buddhism List Editor
> [http://www.h-net.org/~buddhism/]
> Mobile Phone: 090-9310-1787
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords