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 February 6th, 2007, 05:06 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default Element value type in XSLT 1.0

Hallo all,

I want to check a DTD based XML Element value via XSLT 1.0 if it is numeric or alphanumeric. How can I do it? can I for example write

$element = number($element) and that would mean that it is numerical or not or is there another way for it?

Your attitude determines your altitude
__________________
Your attitude determines your altitude
 
Old February 6th, 2007, 05:25 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The clearest is probably

string(number($e)) != 'NaN'

which will be true if the value is numeric.

But if you want to impress people with your deviousness you can do

number($e) = number($e)

which is true only if $e is numeric (i.e. converts to a number other than NaN)

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 6th, 2007, 05:37 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks michael. I have understood the first code but can you clear me how it checks with number($e) = number($e)? Thanks for your reply.

Your attitude determines your altitude
 
Old February 6th, 2007, 05:46 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It relies on a quirk of IEEE 759 floating point arithmetic, namely that the value NaN is considered not equal to itself.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 6th, 2007, 05:51 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much for your reply. I could understand it quite well now.

Your attitude determines your altitude
 
Old February 9th, 2007, 11:26 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have another question? How can I check if an XML value is Alphanumeric or just only Alpha?

Your attitude determines your altitude
 
Old February 9th, 2007, 12:16 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you're only in interested in ASCII, try

$x = translate($x,'0123456789','')

which will be true if there are no digits.

In 2.0 of course you can use regular expressions.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 9th, 2007, 12:20 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael. Sorry but I have another quesiton

How can I express an XOR situation in XSLT 1.0?

Your attitude determines your altitude
 
Old February 9th, 2007, 01:42 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Surely you're capable of working out a solution to that one yourself?

$A or $B and not($A and $B)

or did you mean bitwise XOR?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 13th, 2007, 11:11 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah it is so simple then thanks very much.

Your attitude determines your altitude





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT - fetching element value without getting the samridhis XSLT 4 August 11th, 2008 03:30 AM
XML element with delimited values and XSLT Clark Kent XSLT 15 May 7th, 2008 10:10 AM
Urgent:XSLT element value selection and condition amhicraig XSLT 1 December 4th, 2007 07:57 PM
Copy element into complexType in XSLT 2BOrNot2B XSLT 3 December 20th, 2006 09:09 AM
Write XML element into textbox with XSLT tcstom XSLT 4 July 5th, 2006 04:08 AM





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