Re: [xsl] Could not use matches in Regular Expression (XSLT 2.0)

Subject: Re: [xsl] Could not use matches in Regular Expression (XSLT 2.0)
From: Jack Bush <netbeansfan@xxxxxxxxxxxx>
Date: Tue, 4 May 2010 06:36:24 -0700 (PDT)
Hi Wolfgang,
 
I am trying to match digits between 420000 to 420016 or 49####
with the following regular expression:
 
   
matches(.,'^(4200[0-1][0-6]{6}|49\d{6})$')
   
matches(.,'^(4200[0|1][0-6]{2}|49\d{4})$')
 
However, XSLT transformation
failed with the following error:
    Exception in thread "main"
java.lang.NullPointerException when the data is 420001.
 
One thing I am still
not clear is what is the total number of quantifier {} when the initial
matching numbers have already been provided? So in the case of value 420001,
should the quantifier be {6} (include total number of digits starting from the
1st 4 (4200) already supplied? Or does it only need to quantify the remaining
{2} variation?
 
The last matching for 49#### is simple since there are no
specific patterns required for the last four digits. As a result, the
'^49\d{6}$' but again, I am not sure whether the quantifier should be {6} or
{2} for the same reason already mentioned.
 
Thanks,
Jack
 


----- Original
Message ----
From: Wolfgang Laun <wolfgang.laun@xxxxxxxxx>
To:
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Sent: Mon, 3 May, 2010 5:10:54 PM
Subject: Re:
[xsl] Could not use matches in Regular Expression (XSLT 2.0)

On Mon, May 3,
2010 at 5:47 AM, Jack Bush <netbeansfan@xxxxxxxxxxxx> wrote:
>
> Gentlemen,
>
> Thank you very much for your suggestion that has worked perfectly.
>
> I did
left out the single quotes in the following line:
>
> <xsl:when
test="$TELEPHONE_AREA_CODE = 'FAIRYLAND'">
>
> It was a midnight cut-and-paste
minor blunder.
>
> Btw, so if I want a combination of 2 pattern matching then
it would be along the line of the following:
>
>           matches( .,
'^4\d{6}$ | ^6\d{5}$' ) or <xsl:if test="matches(.,'^4\d{6}$')
| matches(.,'^6\d{5}$')">

This could be a single pattern:
   
'^(4\d{6}|6\d{5})$'


>           matches(., '^4[0-9]{6} | ^6[0-9]{5}') or
<xsl:if test="matches(.,'^4[0-9]{6}') | matches(.,'^6[0-9]{5}">
>
> At the
sametime, is it possible to setup dependencies between multiple pattern
matches such as the following:
>
>           matches( ., '^4\d{6}$ & ^6\d{5}$'
) or <xsl:if test="matches(.,'^4\d{6}$') & matches(.,'^6\d{5}$')">

There is
no '&' (in this sense) in patterns, and it doesn't make
sense: A string cannot
match both distinct, full range (i.e., from
^/start to $/end) at the same
time. What is the spec, verbally?

-W

>           matches(., '^4[0-9]{6} &
^6[0-9]{5}') or <xsl:if test="matches(.,'^4[0-9]{6}') &
matches(.,'^6[0-9]{5}">
>
> ^6\d{5}$' won't be matched unless '^4\d{6} is
matched? Likewise, the same thing applies to '^4[0-9]{6} followed by
^6[0-9]{5}'?
>
> Many thanks again,
>
> Jack
>
>
> ----- Original Message ----
> From: Wolfgang Laun <wolfgang.laun@xxxxxxxxx>
> To:
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Sent: Sun, 2 May, 2010 12:18:21 AM
>
Subject: Re: [xsl] Could not use matches in Regular Expression (XSLT 2.0)
>
>
The pattern must be a string, so enclose it in apostrophes. (Also,
> there is
one opening bracket missing.) To have an exact match, use '^'
> and '$' to
anchor at the beginning and the end. You may simplify using
> a repeat count
(and \d for digit). All together now:
>
>    matches( ., '^4\d{6}$' )
>
> -W
>
> > On Sat, May 1, 2010 at 3:56 PM, Jack Bush <netbeansfan@xxxxxxxxxxxx>
wrote:
> >>
> >> Hi Forum members,
> >>
> >> I
> >> am new to XSLT 2.0 and
would like to do the following basic numeric string pattern
> >> matching
using regular expression:
> >>
> >> <xsl:template
match="ns:p[ns:strong='Telephones:']">
> >>  <xsl:choose>
> >>    < -- If
global parameter $TELEPHONE_AREA_CODE equals to FAIRYLAND -->
> >>  
 <xsl:when test="$TELEPHONE_AREA_CODE = ''FAIRYLAND">
> >>      <xsl:for-each
select="ns:a">
> >>      <-- Only accept the phone number that starts with 4
follow by six digits....   --->
> >>        <xsl:if
test="matches(.,4[0-9][0-9][0-9]0-9][0-9][0-9])">
> >>        
 <phone_number><xsl:value-of select='.'/></phone_number>
> >>        </xsl:if>
> >>      </xsl:for-each>/>
> >>  ......
> >>
> >> However, it is picking up
phone numbers starting with 1 instead. Also tried the starts-with() with the
same outcomes.
> >>
> >> I am using JDK1.6.19, Netbeans 6.7, JDOM 1.1, Saxon
9.1 on Windows XP.
> >>
> >> Your assistance would be much appreciated.
> >>
>
>> Thanks in advance,
> >>
> >> Jack
> >>
> >>
> >>
> >>
> >>
> >>
> >>
--~------------------------------------------------------------------
> >>
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> >> To
unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> >> or e-mail:
<mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> >> --~--
> >>
> >
>
>
--~------------------------------------------------------------------
>
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To
unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail:
<mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --~--
>
>
>
>
>
>
--~------------------------------------------------------------------
>
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To
unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail:
<mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --~--

Current Thread