|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: get Data BETWEEN FromDate and ToDate
><xsl:if test="($doj >= $date1) and ($doj >= $date1)">
Should be amended to:
<xsl:if test="($doj >= $date1) and ($doj <= $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 >=, 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 >= number($fromDate) and $doj <= 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








