Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
It is possible to rewrite this whole construct as:
select=“if (@discount)
then @price - @discount
else @price”/>
or if you really like brevity, as:
select=“@price - (@discount, 0)[1]”/>
This illustrates that when you are calculating values, you often have a choice as to whether to do the work at the XPath level or at the XSLT level. My own preference with simple expressions such as this is to use the XPath approach, unless there is a need to use facilities that are only available at the XSLT level, such as the ability to create new nodes, or the more powerful instructions available in XSLT such as
By far the most common use of
The
Simulating Higher Order Functions
on page 250, which shows a generalized function for finding cycles in any XML data source, regardless of how the relationships are represented.
See Also
xsl:sort
The
Changes in 2.0
The
The value of the sort key may be calculated using an enclosed sequence constructor, as an alternative to using the
select
attribute.
In XSLT 1.0,
A
collation
attribute has been added to allow the collating sequence for strings to be specified by means of a URI, and a
stable
attribute has been added to control how duplicates are handled.
Sorting is now sensitive to the types of the items being sorted. For example, if the sort key values are numeric, they will be compared as numbers rather than as strings.
Format
select? =
expression
lang? = {
nmtoken
}
order? = { “ascending” | “descending”}
collation? = {
uri
}
case-order? = { “upper-first” | “lower-first”}
data-type? = { “text” | “number” |
qname-but-not-ncname
} >
stable? = { “yes” | “no”}
Position
When used in
When used in
Attributes
Name | Value | Meaning |
select optional | XPath Expression | Defines the sort key. The default is . , the context item itself. |
order optional | Attribute value template returning ascending or descending | Defines whether the nodes are processed in ascending or descending order of this key. The default is ascending . |
case-order optional | Attribute value template returning upper-first or lower-first | Defines whether upper-case letters are to be collated before or after lower-case letters. The default is language-dependent. |
lang optional | Attribute value template returning a language code | Defines the language whose collating conventions are to be used. The default depends on the processing environment. |
data-type optional | Attribute value template returning text , number or Lexical QName | Defines whether the values are to be collated alphabetically or numerically, or using a user-defined type. The default is text . |