xsl-list
[Top] [All Lists]

RE: [xsl] Is there a way to tell if a node is an integer?

2006-04-24 13:03:39
Hi Michael,

Thanks much for the information. I didn't catch that in the original message
the person asking the question was using an XSL 2.0 stylesheet...I'm using
an XSL 1.0 stylesheet so that must have been the problem. 

Searching for more info on NaN, I also found this post from Ken Holman which
showed another way to do this:
http://www.xslt.com/html/xsl-list/2002-02/msg01214.html

From the post:
The following will be true if the value is a number:
  test="@value <= 0 or @value > 0"

Thanks again!
Allison

-----Original Message-----
From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com] 
Sent: Saturday, April 22, 2006 2:14 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Is there a way to tell if a node is an integer?



To add to my previous response, if you aren't using schema-aware processing,
then in 2.0 you can test

if test="$x castable as xs:integer"

Note the distinction: we're not testing whether $x *is* an integer, we're
testing whether it can be converted to an integer.

In 1.0 there's no such thing as an integer, but you can test whether a value
is numeric using

string(number($x)) = 'NaN'

and you can test whether it's a whole number using

number($x) = round(number($x))

or if you prefer (this one disallows 3.0)

not(contains($x, '.'))

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: Allison Bloodworth [mailto:abloodworth(_at_)berkeley(_dot_)edu] 
Sent: 22 April 2006 02:31
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Is there a way to tell if a node is an integer?

Hi, 

Is there a way to tell if a node is an integer? I found this message:
http://www.xslt.com/html/xsl-list/2004-10/msg00364.html where 
it appears to say you can use a statement like this:

<xsl:if test="data($a) instance of xs:integer">

But this looks kind of strange, and maybe it is pseudo-code 
because it breaks my transform. 
                                      <xsl:if
test="./Locations/Location/Address/cbc:Room instance of 
xs:integer">Room is an integer</xsl:if>

I want to be able to tell if the cbc:Room node here is an integer:

        <Address>
          <cbc:Postbox languageID="en-us"
languageLocaleID="normalizedString">2105</cbc:Postbox>
          <cbc:Room languageID="en-us"
languageLocaleID="normalizedString">2nd floor</cbc:Room>

          <cbc:StreetName languageID="en-us"
languageLocaleID="normalizedString">Bancroft Way</cbc:StreetName>
          <cbc:CityName languageID="en-us"
languageLocaleID="normalizedString">Berkeley</cbc:CityName>
          <cbc:PostalZone languageID="en-us"
languageLocaleID="normalizedString">94710</cbc:PostalZone>
          <cbc:CountrySubentity languageID="en-us"
languageLocaleID="normalizedString">California</cbc:CountrySubentity>
          <cac:Country>
            <cac:IdentificationCode languageID="en" 
codeListID="ISO3166-1"
codeListVersionID="0.3"
codeListSchemeURI="urn:oasis:names:specification:ubl:schema:xs
d:CountryIdent
ificationCode-1.0" codeListAgencyName="United Nations 
Economic Commission for Europe" codeListName="Country"
codeListAgencyID="6">US</cac:IdentificationCode>

          </cac:Country>
        </Address>

Thanks for any help you can give me!

Allison Bloodworth
Principal Administrative Analyst
Technology Program Office
University of California, Berkeley
(415) 377-8243
abloodworth(_at_)berkeley(_dot_)edu




--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--