[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: get Data BETWEEN FromDate and ToDate

Subject: Re: get Data BETWEEN FromDate and ToDate
From: Rudolf P. Weinmann <rudolf.weinmann@xxxxxxxxxxxx>
Date: Sun, 22 May 2005 07:44:59 +0200
todate
><xsl:if test="($doj &gt;= $date1) and ($doj &gt;= $date1)">
Should be amended to:
<xsl:if test="($doj &gt;= $date1) and ($doj &lt;= $date2)">

As Mukul said, his solution is XSLT 2.0.
Under XSLT 1.0 the result would be empty,
because neither $doj nor $date1 and $date2 can be converted to numbers for
the
comparison in the xsl:if statement.

XSLT 1.0 can do the job as well, see example below.

Using param as a toplevel element, you can pass fromDate and toDate from the
command line or over an API.
I prefere passing them as numbers (see Michael's reasoning) in YYYYMMDD
format.
When comparing the values with &gt;=, they get implicitly converted to
numbers.
I prefere the explicit convertion using the number() function.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:output method="xml" encoding="UTF-8"/>

	<xsl:param name="fromDate" select="'20050403'"/>
	<xsl:param name="toDate" select="'20050405'"/>

	<xsl:template match="Employee">
		<xsl:variable name="doj"
select="number(translate('efghcdab','ab/cd/efgh',@DOJ))"/>
		<xsl:if test="$doj &gt;= number($fromDate) and $doj &lt;= number($toDate)">
			<xsl:call-template name="copy"/>
		</xsl:if>
	</xsl:template>

	<xsl:template match="/|*" name="copy">
		<xsl:copy>
			<xsl:apply-templates select="@*"/>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>

	<xsl:template match="@*">
		<xsl:copy/>
	</xsl:template>

</xsl:stylesheet>

The given input example isn't  wellformed XML.
Employee isn't closed and attribute Empname occurs twice on the first
element.
Corrected input XML:

<?xml version="1.0" encoding="UTF-8"?>
<Employees>
	<Employee Empname="Raj" DOJ="02/04/2005" SftTime="0030"/>
	<Employee Empname="Rajkumar" DOJ="02/04/2005" SftTime="0030"/>
	<Employee Empname="Raja" DOJ="03/04/2005" SftTime="0000"/>
	<Employee Empname="Ravi" DOJ="04/04/2005" SftTime="2330"/>
	<Employee Empname="john" DOJ="05/04/2005" SftTime="1600"/>
	<Employee Empname="gopi" DOJ="06/04/2005" SftTime="0100"/>
	<Employee Empname="ajith" DOJ="13/04/2005" SftTime="2200"/>
</Employees>

Rudolf P. Weinmann

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.