I have what should be a trivial problem. I am using XMLSerializer to
serialize an object. It serializes boolean values as "True" and
"False". I then want to use an XSLT on this XML, and I want to use
one of these booleans in a test. How do I convert one of these to a
boolean in a test?!? I know that I could compare it as a string to
"True" or "False", but that seems extremely crude to me. The
"boolean()" function (which, to me, seems like a misnomer) will always
return "true" since the string is not empty. I'm finding it hard to
believe that there isn't a simple way to turn "0", "false", "False",
"no", "No", "1", "-1", "true", "True", "yes", "Yes", etc. into a
boolean! Have I overlooked something obvious, or is this as difficult
as it appears?
Thanks!
Brad. 4 18530
"Bradley Plett" <pl****@hotmail.com> wrote in message news:bo********************************@4ax.com... How do I convert one of these to a boolean in a test?!? I know that I could compare it as a string to "True" or "False", but that seems extremely crude to me.
Looks like a clear solution to me.
I'm finding it hard to believe that there isn't a simple way to turn "0", "false", "False", "no", "No", "1", "-1", "true", "True", "yes", "Yes", etc. into a boolean!
Don't forget "verdad", "falso", "ja", "nein", et al.
"boolean()" function (which, to me, seems like a misnomer) will always return "true" since the string is not empty.
It's either that definition of falseness, or every XPath processor
will need a world dictionary.
If you must use boolean(), then try removing the characters in the word
"False" to make it an empty string.
boolean(translate(string(@attrName),"fFalse",""))
Have I overlooked something obvious, or is this as difficult as it appears?
Not to sound like the Oracle from the movie, "The Matrix," but I think
what you're overlooking is.. you already know the answer. ;-)
Derek Harmon
"Bradley Plett" <pl****@hotmail.com> wrote in message news:bo********************************@4ax.com... How do I convert one of these to a boolean in a test?!? I know that I could compare it as a string to "True" or "False", but that seems extremely crude to me.
Looks like a clear solution to me.
I'm finding it hard to believe that there isn't a simple way to turn "0", "false", "False", "no", "No", "1", "-1", "true", "True", "yes", "Yes", etc. into a boolean!
Don't forget "verdad", "falso", "ja", "nein", et al.
"boolean()" function (which, to me, seems like a misnomer) will always return "true" since the string is not empty.
It's either that definition of falseness, or every XPath processor
will need a world dictionary.
If you must use boolean(), then try removing the characters in the word
"False" to make it an empty string.
boolean(translate(string(@attrName),"fFalse",""))
Have I overlooked something obvious, or is this as difficult as it appears?
Not to sound like the Oracle from the movie, "The Matrix," but I think
what you're overlooking is.. you already know the answer. ;-)
Derek Harmon
Bradley Plett wrote: I have what should be a trivial problem. I am using XMLSerializer to serialize an object. It serializes boolean values as "True" and "False".
Well, you are wrong. It serializes them as "true" and "false" as per XML
Schema xs:boolean type. xs:boolean defines "true", "1" and "false", "0"
as the only valid values.
I then want to use an XSLT on this XML, and I want to use one of these booleans in a test. How do I convert one of these to a boolean in a test?!? I know that I could compare it as a string to "True" or "False", but that seems extremely crude to me. The "boolean()" function (which, to me, seems like a misnomer) will always return "true" since the string is not empty. I'm finding it hard to believe that there isn't a simple way to turn "0", "false", "False", "no", "No", "1", "-1", "true", "True", "yes", "Yes", etc. into a boolean! Have I overlooked something obvious, or is this as difficult as it appears?
In XPath 1.0 (which was released when XML Schema was in early drafts)
one has to check both "1" and "true":
<xsl:if test="foo = 'true' or foo = 1">
PS. It's fixed in XPath 2.0.
--
Oleg Tkachenko [XML MVP] http://blog.tkachenko.com
Bradley Plett wrote: I have what should be a trivial problem. I am using XMLSerializer to serialize an object. It serializes boolean values as "True" and "False".
Well, you are wrong. It serializes them as "true" and "false" as per XML
Schema xs:boolean type. xs:boolean defines "true", "1" and "false", "0"
as the only valid values.
I then want to use an XSLT on this XML, and I want to use one of these booleans in a test. How do I convert one of these to a boolean in a test?!? I know that I could compare it as a string to "True" or "False", but that seems extremely crude to me. The "boolean()" function (which, to me, seems like a misnomer) will always return "true" since the string is not empty. I'm finding it hard to believe that there isn't a simple way to turn "0", "false", "False", "no", "No", "1", "-1", "true", "True", "yes", "Yes", etc. into a boolean! Have I overlooked something obvious, or is this as difficult as it appears?
In XPath 1.0 (which was released when XML Schema was in early drafts)
one has to check both "1" and "true":
<xsl:if test="foo = 'true' or foo = 1">
PS. It's fixed in XPath 2.0.
--
Oleg Tkachenko [XML MVP] http://blog.tkachenko.com This discussion thread is closed Replies have been disabled for this discussion. Similar topics
9 posts
views
Thread by lawrence |
last post: by
|
10 posts
views
Thread by Sylvain Thenault |
last post: by
|
1 post
views
Thread by nick |
last post: by
|
72 posts
views
Thread by Paminu |
last post: by
|
10 posts
views
Thread by Daniel Crespo |
last post: by
|
59 posts
views
Thread by Pierre Quentel |
last post: by
|
4 posts
views
Thread by =?utf-8?B?Qm9yaXMgRHXFoWVr?= |
last post: by
|
25 posts
views
Thread by Koliber (js) |
last post: by
| | | | | | | | | | | |