Altova Mailing List Archives

Re: [xsl] XPath 2.0 Regex misunderstanding

From: "Mukul Gandhi" <gandhi.mukul@--------->
Date: 1/19/2007 5:03:00 PM
If the XML is:


and, XSLT is:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="" version="2.0">

<xsl:output method="xml" indent="yes" />

<xsl:template match="/x">
   <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>


and if the XSLT processor produces output:

<?xml version="1.0" encoding="UTF-8"?>

I feel, XSLT processor is compliant. And this is exactly what Saxon
8.8J is doing.

On 1/19/07, cknell@xxxxxxxxxx <cknell@xxxxxxxxxx> wrote:
I have a date element:



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:


While these failed:


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?
Charles Knell
cknell@xxxxxxxxxx - email

Mukul Gandhi


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.