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

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

Any additional system properties returned by this function are implementation-defined. Such properties should either be in a namespace specific to the vendor, or in no namespace. Some products provide access to environment variables or Java system properties using this mechanism; this can be particularly useful as a way of parameterizing the
use-when
construct.

Usage

The
system-property()
function can be used to determine details about the processor running the stylesheet, either for display purposes (for example, to produce a comment in the generated output), or to apply conditional logic.

The function is especially useful when used in conjunction with the
use-when
attribute. For example, you can import a schema only if the processor is schema-aware by writing

           use-when=“system-property(‘xsl:is-schema-aware’) eq ‘yes’”/>

You can use the same approach on

and

to include entire stylesheet modules conditionally. If the processor allows you to access environment variables set from the operating system shell, this provides a powerful way of maintaining different variants of your stylesheet for different processing scenarios, rather like
#ifdef
directives in C.

Generally, it is best to avoid testing the system version to see whether particular features are available, unless there is no other way of doing so. The functions
function-available()
and
element-available()
and the

instruction often serve this need better, and the forward- compatibility features described on page 130 in Chapter 3 can be used to ensure that a stylesheet can work with processors that implement an older dialect of XSLT.

However, there are some cases where testing
system-property(‘xsl:version’)
is the only practical way of discovering whether a feature is available. For example, the XSLT 2.0 working draft introduces the ability to use a tree-valued variable (or a result tree fragment, as it is known in XSLT 1.0) as a document node, in contexts such as

and

. Since this feature does not introduce any new functions or XSLT elements, the only practical way to test whether it is available is to check the XSLT version supported.

Examples

The following code outputs a documentary comment into the generated HTML.


   

     Generated with XSLT stylesheet 

     using 

     version 

   


See Also

element-available()
page 764

function-available()
on page 792


on page 316 in Chapter 6

timezone-from-date, timezone-from-dateTime, timezone-from-time

These three functions extract the timezone component from an
xs:date
,
xs:time
, or
xs:dateTime
value. For example, for a user in California,
timezone-from-dateTime(current-dateTime
())
typically returns the dayTimeDuration
-PT8H
.

Signature

Argument
Type
Meaning
input
xs:date?
,
xs:time?
, or
xs:dateTime?
The value from which the timezone component is to be extracted. The type of the supplied argument must correspond to the type implied by the function name.
Result
xs:dayTimeDuration?
The timezone, expressed as a duration
.

Effect

The function returns the timezone component of the supplied
xs:date
,
xs:time
, or
xs:dateTime
.

If the argument is an empty sequence, or if it is a date, time, or dateTime containing no timezone, then the result is an empty sequence. Otherwise, the function returns the timezone from the specified value. The timezone is returned in the form of an
xs:dayTimeDuration
value giving the offset from UTC (or Greenwich Mean Time, in common language).

If you want the timezone as a numeric value in hours, divide it by
xs:dayTimeDuration (“PT1H”)
.

Examples

Expression
Result
timezone-from-date(xs:date(“2008-02-28”))
()
timezone-from-dateTime(xs:dateTime(“2008-02-28T13:00:00-06:00”))
-PT6H
timezone-from-time(xs:time(“13:00:00+01:00”))
PT1H
timezone-from-dateTime(xs:dateTime(“2008-07-31T23:00:00Z”))
PT0 S

See Also

adjust-date/time-to-timezone
on page 715

current-date()
,
-dateTime()
,
-time()
on page 738

format-date()
,
-dateTime()
,
-time()
on page 781

implicit-timezone()
on page 806

tokenize

The
tokenize()
function splits a string into a sequence of substrings, by looking for separators that match a given regular expression.

For example,
tokenize(“12, 16, 2”, “,\s*”)
returns the sequence
(“12”, “16”, “2”)
.

Other books

Her Texas Family by Jill Lynn
Redeemer by Katie Clark
SEALs of Summer 2: A Military Romance Superbundle by S.M. Butler, Zoe York, Cora Seton, Delilah Devlin, Lynn Raye Harris, Sharon Hamilton, Kimberley Troutte, Anne Marsh, Jennifer Lowery, Elle Kennedy, Elle James
Go Big by Joanna Blake
A Covert Affair by Jennet Conant
Act 2 (Jack & Louisa) by Andrew Keenan-bolger, Kate Wetherhead
The Boleyn Deceit by Laura Andersen