Subject: Re: [xsl] XPath 2.0 Regex misunderstanding From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Fri, 19 Jan 2007 22:32:39 +0530 |
<x> <DATE>07/18/2006</DATE> <DATE>07/12/2006</DATE> <DATE>09/25/2006</DATE> <DATE>10/24/2006</DATE> <DATE>10/18/2006</DATE> <DATE>10/10/2006</DATE> <DATE>10/02/2006</DATE> <DATE>01/19/2006</DATE> </x>
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="/x"> <result> <xsl:for-each select="DATE"> <xsl:if test="matches(.,'[0-1][0-2]/[0-3][0-9]/2006')"> <bad-date><xsl:value-of select="." /></bad-date> </xsl:if> </xsl:for-each> </result> </xsl:template>
<?xml version="1.0" encoding="UTF-8"?> <result> <bad-date>10/24/2006</bad-date> <bad-date>10/18/2006</bad-date> <bad-date>10/10/2006</bad-date> <bad-date>10/02/2006</bad-date> <bad-date>01/19/2006</bad-date> </result>
I feel, XSLT processor is compliant. And this is exactly what Saxon 8.8J is doing.
I have a date element:
example
<DATE>11/01/2006</DATE>
I'm trying to write an XPath 2.0 Regex to winnow some of the more obvious date format errors. I have tried for about a half-hour, and I admit to being stumped.
Here is the relevant part of the template:
<xsl:when test="matches(DATE,'[0-1][0-2]/[0-3][0-9]/2006')"><bad-date /></xsl:when>
These dates passed the test:
<DATE>07/18/2006</DATE> <DATE>07/12/2006</DATE> <DATE>09/25/2006</DATE>
While these failed:
<DATE>10/24/2006</DATE> <DATE>10/18/2006</DATE> <DATE>10/10/2006</DATE> <DATE>10/02/2006</DATE> <DATE>01/19/2006</DATE>
It appears any value with a "1" in either the first or second position is failing.
What I am trying to achieve is:
First character is either a "0" or "1" Second character is in the range of 0-2 Third character is "/" Fourth character is in the range of 0-3 Fifth character is in the range of 0-9 Sixth character is "/" Text ends with the string "2006".
Can someone point out where I'm going wrong? Thanks. -- Charles Knell cknell@xxxxxxxxxx - email
-- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XPath 2.0 Regex misunders, Michael Kay | Thread | Re: [xsl] XPath 2.0 Regex misunders, Abel Braaksma |
RE: [xsl] XPath 2.0 Regex misunders, Michael Kay | Date | Re: [xsl] XPath 2.0 Regex misunders, Abel Braaksma |
Month |