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

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

Usage

Standalone XPath 2.0 does not provide any facilities for formatting the date and time for display. You can do this in XSLT 2.0 using the functions
format-date()
,
format-dateTime()
, and
format-time()
.

See Also

adjust-date/time-to-timezone()
functions described on page 738

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

X-from-date/time/dateTime()
functions described in their alphabetical position in this chapter, where X is one of
year
,
month
,
day
,
hours
,
minutes
,
seconds
, or
timezone
.

current-group

This function is available in XSLT only
.

The
current-group()
function returns the set of items making up the group that is currently being processed using the

instruction.

Signature

There are no arguments.

Type
Meaning
Result
item()*
A sequence of items, specifically the sequence that is being processed in the current iteration of an

instruction

Effect

When the stylesheet starts executing, there is no current group; the
current-group()
function then returns an empty sequence.

The

instruction, described in Chapter 6, page 326, takes as input a sequence of items (called the population) and a grouping expression or pattern. It allocates each item in the population to zero or more groups of items, and then processes each group in turn. While it is processing each group, the
current-group()
function returns the sequence of items that participate in that group.

The
current-group()
function does not need to be called textually within the

instruction. Its scope is dynamic, and the current group remains available in called templates unless another nested

instruction is evaluated. On completion of an

instruction, it reverts to its previous value.

The
current-group()
function can also be called while evaluating the sort key in an

element contained within the

instruction. This affects the order in which groups are processed. In this context,
current-group()
refers to the group whose sort key is being calculated. For example, to sort groups in order of decreasing size, write

.

On entry to a stylesheet function, the current group is an empty sequence.

Usage and Examples

See

on page 326 in Chapter 6

See Also


on page 326 in Chapter 6

current-grouping-key()
in the following section

current-grouping-key

This function is available in XSLT only
.

The
current-grouping-key()
function returns the value of the grouping key that defines the group currently being processed using the

instruction. The grouping key is the value of the expression in the
group-by
or
group-adjacent
attribute. When grouping is done using patterns, there is no current grouping key.

Signature

There are no arguments.

Type
Meaning
Result
xs:anyAtomicType?
This is the value of the
group-by
or
group-adjacent
expression that is shared by all the items in the current group.
The return type indicates that the grouping key can be of any atomic type; for example
,
xs:string
,
xs:decimal
,
or
xs:date
.
When there is no current group, the function returns an empty sequence
.

Effect

When the stylesheet starts executing, there is no current grouping key; the
current-grouping-key()
function then returns an empty sequence.

The

instruction, described in Chapter 6, page 326, takes as input a sequence of items called the population and a grouping expression or pattern. If the grouping criteria are defined using the
group-by
or
group-adjacent
attributes, then while each group is being processed, the
current-grouping-key()
function returns the grouping key value that characterizes that group.

If the grouping criteria are defined using the
group-starting-with
or
group-ending-with
attributes of

, the current grouping key is an empty sequence.

The
current-grouping-key()
function does not need to be called textually within the

instruction. Its scope is dynamic, and the current grouping key remains available in called templates unless another nested

instruction is evaluated. On completion of an

instruction, it reverts to its previous value.

The
current-grouping-key()
function can also be called while evaluating the sort key in an

element contained within the

instruction. This affects the order in which groups are processed. In this context,
current-grouping-key()
refers to the group whose sort key is being calculated. For example, to sort groups in descending order of their grouping key, write

.

On entry to a stylesheet function, the current grouping key is an empty sequence.

Usage and Examples

The following example groups a set of books by the name of the author. For each author, a section heading is displayed giving the name of the author, followed by a list of the books written by this author. The authors are sorted by name. A book that has several authors will be listed more than once.


  

  

  


See Also

current-group()
on page 739


, page 326 in Chapter 6

current-time

See
current-date()
on page 738

data

The
data()
function returns the atomized value of a sequence. This means that any nodes in the input sequence are replaced by their typed values.

Signature

Argument
Type
Meaning
sequence
item()*
The input sequence
Result
xs:anyAtomicType*
A sequence based on the input sequence, in which all nodes have been replaced by their typed values

Effect

Atomization is a process that is invoked implicitly when a sequence containing nodes is used in a context where atomic values are expected. For example, if you write
@a+42
, the attribute node represented by the expression
@a
is atomized to obtain a number, which is then added to 42. The
data()
function invokes atomization explicitly, and is used either in a context where implicit atomization does not occur (for example, the argument to the
count()
function is not atomized), or in cases where you want to make it clear to the reader what is going on.

Atomization applies the following process to each item in the input sequence. The results are concatenated together retaining the original sequence order:

  • If the input sequence contains an atomic value, the atomic value is added to the result sequence unchanged.
  • If the input sequence contains a node, the typed value of the node is added to the result sequence.

The typed value of a node depends on its type annotation. In the absence of a schema, or when the type annotation is
xs:untypedAtomic
or
xs:untyped
, the typed value is the same as the string value, but the resulting atomic value remains an
xs:untypedAtomic
value rather than a string, which allows it to be used in contexts (for example, as an operand of
+
) where a string would not be allowed.

Other books

Faster (Stark Ink, #3) by Dahlia West
The Before by Emily McKay
Parallel Worlds by Michio Kaku
Lisa Renee Jones by Hot Vampire Seduction
Wanderlust Creek and Other Stories by Elisabeth Grace Foley
Tycoon Takedown by Ruth Cardello
Wilson Mooney Eighteen at Last by Gretchen de la O
Tumblin' Dice by John McFetridge
Santorini by Alistair MacLean
The Woman from Hamburg by Hanna Krall