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 May 29th, 2008, 08:40 AM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default Validate a GUID(UUID)

I'm been given the task to validate some data using XSLT. One of the things I've got to validate is a Universally Unique Identifier in the format (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.X)
I should explain what I mean when I say validate.

An incoming document has a huge amount of elements. I'm simply using XSLT to check to make sure data within the elements exists if required. And If it's there, that it's in the right format.

I would think validating a UUID would be something that has been done before in XSLT. I could write it, but you know how use programmers don't like to repeat things that other people have already done.

Anyone written a UUID validation before they'd be willing to share?
 
Old May 29th, 2008, 08:52 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

The page http://www.geekzilla.co.uk/View8AD53...1BC663848E.htm has a regular expression (and .NET C# code).
If you use XSLT 2.0 then you might be able to use that regular expression with XSLT/XPath instead and the matches function that exists in XPath 2.0: http://www.w3.org/TR/xpath-functions/#func-matches

--
  Martin Honnen
  Microsoft MVP - XML
 
Old May 29th, 2008, 10:02 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Can you tell us, in English, what rules you think a valid UUID needs to obey?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 29th, 2008, 11:12 AM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default

Using the Regular Expression on the link above, and making small adjustments, I was able to use the following as an XPath.

matches(., '^([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}.([0-1]){1}')

It works perfectly fine for my application. With some small adjustments to the Reg Expression I found <xsl:analyze-string /> much more useful.

In regards to Michael's question. My application does not require a particularly deep validation. I just need to make sure that the UUID is in a canonical form. (128 bit, 32 hexadecimal digits, in the form 8-4-4-4-12 for a total of 36 characters.) I do not need to check for a specific version of UUID. White space has been handled by other templates in my particular XSLT.

Thanks very much!
 
Old May 29th, 2008, 11:30 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Just for the record, you can also do this kind of validation using translate():

translate($in, '0123456789abcdefABCDEF', '0') =
'00000000-0000-0000-0000-000000000000'

which might be faster.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 29th, 2008, 11:33 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry, that should be

translate($in, '0123456789abcdefABCDEF', '000000000000000000000000') =
'00000000-0000-0000-0000-000000000000'


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 29th, 2008, 11:35 AM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default

*pulls out my books*

You always have insightful, unique ways to make use of XSLT. Thanks again.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Ask IIS for a GUID? Raconteur ASP.NET 2.0 Professional 2 April 25th, 2007 03:25 PM
GUID cdhansen BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 October 21st, 2006 04:56 AM
generating two different GUID shaileshmark General .NET 5 August 1st, 2004 01:25 PM
Creating a GUID xgbnow Visual C++ 1 May 6th, 2004 11:10 AM
Dynamic GUID? Klavs Pedersen Visual C++ 1 October 15th, 2003 12:33 PM





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