[Accessibility conventions are described at the bottom of the page]
*** This is a free preview excerpt of a commercial publication. ***

9. Sorting and grouping
[> A.][< 8.0][^^^]
9.0 Sorting and grouping
[> A.][< 9.][^^][^^^]
This chapter covers how to arrange the construction of results in ordered fashion.
Sorting
An important part of many transformations is the need to re-order the information in source tree nodes into a sorted order for processing into result tree nodes:
[[1] - designed for sorting the context list using multiple criteria
[[2] - each criterion is a single value calculated for each node
 [2] - value may be simple node value or may be any XPath evaluation relative to node
][1] - the source tree is untouched during sorting
[[2] - items being sorted are selected from the tree and the selection itself is sorted, not the tree
][1] - sorting can be language based, numeric based, type-based or based on custom semantics
 [1] - the context list can be any arbitrary sequence
 [1] - multiple keys are used to sort clumps of equal values by other values
[[2] - e.g. a secondary key is used when the primary key finds clumps of equal values
[[3] - the secondary key is only applied to the clumped values, maintaining the set of clumped values in the same position of the primary sort
][2] - e.g. a tertiary key is used when the secondary key finds clumps of equal values
[[3] - the tertiary key is only applied to the clumped values after the secondary sort, maintaining the set of clumped values in the same position of the secondary sort, in the same position of the primary sort
][2] - leftover clumped values after all keys are accommodated are left in context list sequence order
]]
Grouping and uniqueness
Another important part of many transformations is the need to infer structure from the results of sorting information, which is a process often called "grouping":
[[1] - collecting information while separating and grouping it by common values
[[2] - i.e. grouping the clumps under the value that created the clump
 [2] - selecting a single piece of composite information obtains all components
 [2] - a simple sort doesn't partition the composite information into constituent pieces
][1] - specific application of the generalized problem of finding unique values from a set
[[2] - often necessary to find unique values in a set of values
 [2] - unique values make up the group headings
][1] - [T1.0]no explicit support for grouping under duplicate source tree node values
 [1] - [T2.0]explicit support for grouping under duplicate source tree node values
]
[T1.0]This chapter covers three techniques of using XSLT 1.0 to group constructs when processing:
[[1] - using reverse-document-order axes
 [1] - the "Muenchian Method" of using <xsl:key>
 [1] - using variables
]
[T2.0]This chapter also covers the built-in XSLT 2.0 facility for grouping
[[1] - group-adjacent, group-by, group-starting-with and group-ending-with
]
The XSLT instructions covered in this chapter are:
[[1] - [<xsl:sort>]
[[2] - specify a criterion with which to sort a set of nodes
][1] - [T2.0] [<xsl:perform-sort>]
[[2] - specify the criteria with which to sort a sequence of items
][1] - [T2.0] [<xsl:for-each-group>]
[[2] - act on a set of items according to grouping criteria
]]
The XSLT functions covered in this chapter are:
[[1] - [T2.0] [current-grouping-key]()
[[2] - returns the value by which members of the current set of grouped items are grouped
][1] - [T2.0] [current-group]()
[[2] - returns the members of the current set of grouped items
]]

*** This is a free preview excerpt of a commercial publication. ***

This is an accessible version of Crane's commercial training material. The content has been specifically designed to assist screen reader software in viewing the entire textual content. Figures are replaced with text narratives.

Navigation hints are in square brackets:
[Tx.x] and [Fx.x] are textual representations of the applicability icons;
[digit] indicates list depth for nested lists;
[link [URL]] indicates the URL of a hyperlink if different than link;
[EXAMPLE] indicates an example listing of code;
[FIGURE] indicates the presence of a figure replaced by its description;
[>] jumps forward;
[<] jumps backward;
[^] jumps to start of the section;
[^^] jumps to the start of the chapter;
[^^^] jumps to the table of contents.
Suggestions for improvement are welcome: [info@CraneSoftwrights.com]
Book sales: [http://www.CraneSoftwrights.com/links/trn-acc.htm]
Information: [http://www.CraneSoftwrights.com/links/info-acc.htm]
This content is protected by copyright and, as there are no means to protect this accessible version from plagiarism, please do not make any commercial edition available to others.

+//ISBN 978-1-894049::CSL::Courses::PTUX//DOCUMENT Practical Transformation Using XSLT and XPath 2011-02-11 21:00UTC//EN
Practical Transformation Using XSLT and XPath
Fourteenth Edition - 2011-02-11
ISBN 978-1-894049-24-5
Copyright © Crane Softwrights Ltd.