RE: [xsl] Fundimentle Predicate Problem or Bug??

Subject: RE: [xsl] Fundimentle Predicate Problem or Bug??
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 18 Sep 2008 00:05:25 +0100
Your stylesheet says version="2.0" but are you actually using an XSLT 2.0
processor? If you give this to a 1.0 processor it will treat FixtureDate
&lt;= '2010-01-01' as a numeric comparison, convert the date to the number
NaN, and return false because all comparisons with NaN are false.

Even with a 2.0 processor it would be more robust to do a date comparison
rather than a string comparison - string collations can play funny tricks
with hyphens.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Chris Hughes [mailto:chris_hughes22@xxxxxxxxxxx] 
> Sent: 17 September 2008 14:53
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Fundimentle Predicate Problem or Bug??
> 
> Hi
> 
> I tried asking for help a while back on this, anyway now I 
> have worked out exactly where my issue is and will provide 
> examples below.
> 
> Assume this data....
> 
> <?xml version="1.0" encoding="utf-8"?>
> <ORCB082>
>    <ROWSET>
>       <ROW num="1">
>         <Fixture>
>             <FixtureDate>2008-10-17</FixtureDate>
>             <FixtureDayText>DAY ONE TEST</FixtureDayText>
>             <Race>
>                <RaceType>S</RaceType>
>             </Race>
>             <Race>
>                <RaceType>H</RaceType>
>             </Race>
>          </Fixture>
>       </ROW>
>    </ROWSET>
> </ORCB082>
> 
> 
> Stylesheet 1
> ------------
> 
> This stylesheet outputs "DAY ONE TEST" message, IMO it should 
> match no records and not output anything.
> 
> <?xml version="1.0"?>
>   <xsl:stylesheet version="2.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>                                 
> xmlns:xs="http://www.w3.org/2001/XMLSchema";>
>   <xsl:output method="text" indent="yes"/> 
> 
>   <xsl:template match="/">
> 
>   <xsl:for-each 
> select="/ORCB082/ROWSET/ROW/Fixture[FixtureDate &gt;= 
> '2008-01-01' and FixtureDate &lt;= '2010-01-01' and
>                                                     
> Race/RaceType &gt;= 'R' and Race/RaceType &lt;= 'R']" >
> 
>     <xsl:message><xsl:value-of select="FixtureDayText"/></xsl:message>
>   </xsl:for-each>
>   </xsl:template>
> </xsl:stylesheet>
> 
> 
> Stylesheet 2
> ------------
> 
> This stylesheet outputs nothing - which is what I would 
> expect, but essentially is stylesheet 1 not performing the 
> same logic as 2?
> 
> 
> <?xml version="1.0"?>
>   <xsl:stylesheet version="2.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>                                 
> xmlns:xs="http://www.w3.org/2001/XMLSchema";>
>   <xsl:output method="text" indent="yes"/> 
> 
>   <xsl:template match="/">
> 
>   <xsl:for-each 
> select="/ORCB082/ROWSET/ROW/Fixture[FixtureDate &gt;= 
> '2008-01-01' and FixtureDate &lt;= '2010-01-01' and
>                                                     
> Race/RaceType = 'R']" >
> 
>     <xsl:message><xsl:value-of select="FixtureDayText"/></xsl:message>
>   </xsl:for-each>
>   </xsl:template>
> </xsl:stylesheet>
> 
> Conclusion
> -----------
> 
> Like so many of us working in the XML / XSLT world I find it 
> difficult to adjust to a different way of working.  
> Essentially had I wrote this logic in SQL or 4GL or VB etc 
> etc I'd be sure that it would work.  I hope nobody is 
> offended by me suggesting this may be a bug!
> 
> Thanks in advance.
> 
> Chris

Current Thread