XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (89 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
13.19Mb size Format: txt, pdf, ePub
ads

In the sections that follow, I will describe the built-in atomic types in a number of groups. These are my own categories, not anything that comes from the specifications themselves:

  • The major atomic types
    :
    xs:anyURI
    ,
    xs:boolean
    ,
    xs:date
    ,
    xs:dateTime
    ,
    xs:decimal
    ,
    xs:double
    ,
    xs:integer
    ,
    xs:QName
    ,
    xs:string
    ,
    xs:time
    ,
    xs:dayTimeDuration
    , and
    xs:yearMonthDuration
    . These are the only atomic types that are directly supported in the XPath library of functions and operators for anything but the most trivial of operations. They are therefore the ones you are likely to be using most of the time.
  • The minor atomic types
    : These are defined as primitive types in XML Schema, but they are not well supported by XPath, and you are unlikely to use them very often. These are
    xs:gYear
    ,
    xs:gYearMonth
    ,
    xs:gMonth
    ,
    xs:gMonthDay
    ,
    xs:gDay
    ,
    xs:duration
    ,
    xs:float
    ,
    xs:hexBinary
    ,
    xs:base64Binary
    , and
    xs:NOTATION
    .
  • The derived numeric types
    : These are defined by restriction from the
    xs:integer
    type. They all define integers with a limited range of values, for example,
    xs:positiveInteger
    ,
    xs:short
    ,
    xs:unsignedByte
    .
  • The derived string types
    : These are defined by restriction from
    xs:string
    . They include types like
    xs:token
    and
    xs:NCName
    that restrict the syntax of the string and define the treatment of whitespace.
  • The type
    xs:untypedAtomic
    : This represents values whose type is unknown, because the value has not been validated by a schema processor. This is a chameleon type, whose values can be used freely in any context, provided that the value can be converted at runtime to the type that's expected.

There are two ways to use these atomic types:

  • You can use them in a schema to define the types of elements and attributes. When you do this, the result of validating an XML document against this schema will be that the elements and attributes acquire a type annotation of the appropriate atomic type, and the typed value of the nodes (which is what you typically get when you use the node as input to an operation such as addition) will be the atomic value of the relevant type.
  • You can manipulate atomic values of these types in your XPath expressions. For example, if you compare two strings, the result is a boolean, that is, a value of type
    xs:boolean
    . This value has never been anywhere near an XML document, let alone an XML Schema validator, but it is an
    xs:boolean
    all the same.

The Major Atomic Types

This section describes the most important atomic types used in XPath expressions, in alphabetical order. These types are chosen because they are the ones that are supported in the standard library of functions and operators defined in XPath, in particular the functions listed in Chapter 13. They are probably the types you will use 95% of the time.

xs:anyURI

This type is intended to hold URIs, in the widest sense of the term. This includes:

  • Absolute URIs such as
    http://www.w3.org/
  • Relative URI references such as
    ../index.html
  • URIs with a fragment identifier at the end, separated by a
    #
    character: for example
    http://www.w3.org/TR/xpath20#Introduction
    or simply
    #Introduction
  • Unescaped URIs such as
    file:///My Documents/biog.doc
    . Technically, this is not a URI because it contains a space character. To make it into a URI, the space must be escaped so it appears as
    file:///My%20Documents/biog.doc
    . A number of specifications such as XML Linking explicitly allow a URI to be held in its unescaped form (because it isn't a real URI until it is escaped, I sometimes refer to it as a
    wannabe-URI
    ). And although these aren't real URIs, XML Schema explicitly allows them to appear in an
    xs:anyURI
    value.
BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
13.19Mb size Format: txt, pdf, ePub
ads

Other books

Appointed to Die by Kate Charles
My Biker Bodyguard by Turner, J.R.
The Battle of the Crater: A Novel by Gingrich, Newt, Forstchen, William R., Hanser, Albert S.
DowntoBusiness by Dena Garson
Rite Men for Maya by Renquist, Zenobia
Wrapped in the Flag by Claire Conner
Havana Lunar by Robert Arellano