Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 28th, 2006, 03:53 AM
Authorized User
 
Join Date: May 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Checking regex with replace and URI test

We tried to figure out how to test a valid date pattern where also a year is valid. Herefore we needed a "only ONE of the patterns must be true" construction but when we use the OR in the regexp
the "match" function acts more likely as a find function. Ergo an OR returns true if ONE or MORE expressions is true.
This is the Date check regex (remove the LineBreaks I put that in for readability):

((P)(((([1-9])(\d)*)(J)){{0,1}}((([1-9])(\d)*)(M)){{0,1}}((([1-9])
(\d)*)(D)){{0,1}}))(((T(([1-9])(\d)*)(H))((([1-9])(\d)*)(M)){{0,1}}
((([1-9])(\d)*(\.((\d)*([1-9])(\d)*)){{0,1}})(S)){{0,1}})|((T(([1-9])
(\d)*)(M))((([1-9])(\d)*(\.((\d)*([1-9])(\d)*)){{0,1}})(S)){{0,1}})
|((T(([1-9])(\d)*(\.((\d)*([1-9])(\d)*)){{0,1}})(S)){{0,1}}))

We check the date but also only a year like 2004 is valid. So if I enter 2004-20-18 (which is no valid date) returns true when I use the match function, because the first part (2004) is a valid expression. But when I use the "replace" function it works OK. Because if a specific part of the OR does not match the function will return nothing. If more parts are true it returns more replace characters.

test = "replace(./datetime,'((P)(((([1-9])(\d)*)(J)){{0,1}}((([1-9])(\d)*)(M))
{{0,1}}((([1-9])(\d)*)(D)){{0,1}}))(((T(([1-9])(\d)*)(H))((([1-9])(\d)*)
(M)){{0,1}}((([1-9])(\d)*(\.((\d)*([1-9])(\d)*)){{0,1}})(S)){{0,1}})
|((T(([1-9])(\d)*)(M))((([1-9])(\d)*(\.((\d)*([1-9])(\d)*)){{0,1}})(S)){{0,1}})|
((T(([1-9])(\d)*(\.((\d)*([1-9])(\d)*)){{0,1}})(S)){{0,1}}))','x') = 'x'"

So if I check "A or B" and it turns out that A and B are true the function returns "xx" but when you want to check if there is only but one true I check if the return value is equal to "x".

We also have made a regular expression for a URI it was huge...and could not be used in the xslt because of the many "&" characters in it. We tried the "instance of" construction but that also did not work.
But thanx for the WROX book "XPATH2.0 programmers reference" that explains everything I needed, the construction:
test="data('http:www.wrox.com') castable as xsd:anyURI" works fine to test a valid URI. (or do I reveal now some secrets from the book)
so thanx for that.
 
Old July 28th, 2006, 05:19 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm sorry, I'm having difficulty working out exactly what you are trying to do.

My advice would be to avoid trying to do this all with regular expressions. Use the regex functionality to pick out something that looks like a plausible date, and then use other techniques (eg. $x castable as xs:date) to see if it is in fact a valid date.

Perhaps if you explained your overall requirement (that is, what are the input and output of your transformation) it would be clearer, and alternative designs might suggest themselves.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
replace text without using regex mrame XSLT 7 July 28th, 2008 09:12 AM
Issue with replace function using regex avator BOOK: Beginning Regular Expressions 0 May 26th, 2008 03:46 AM
chapter 2, error uri cannot be resolved in either boylevel BOOK: Beginning JavaServer Pages 2 November 21st, 2007 12:54 PM
How do I get only the filename of the reffered URI shekhar_249 General .NET 1 August 25th, 2006 06:40 AM
Referrer and Uri druid2112 General .NET 1 April 20th, 2004 12:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.