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

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

substring(“xyz”, 1, $b * (1 div 0))

exploiting the fact that
1 div 0
under XPath 1.0 is infinity, and zero times infinity is NaN. This obscure construct provided XPath 1.0 programmers with a substitute for a conditional expression.

If you try to run this code under XPath 2.0, it will fail:
1 div 0
is an
xs:decimal
division rather than an
xs:double
division, and the
xs:decima
l type has no infinity value. If you need to rewrite this so that it works under both XPath 1.0 and XPath 2.0, the simplest way is to replace the
1 div 0
by a very large but finite number. In XSLT, you can define this as a global variable. Remember, though, that exponential notation for numbers is not available in XPath 1.0.

See Also

substring-after()
in the following section

substring-before()
on page 887

string-length()
on page 880

contains()
on page 730

substring-after

The
substring-after()
function returns that part of a string value that occurs after the first occurrence of some specified substring.

For example, the expression
substring-after(‘print=yes’
,
‘=’)
returns
yes
.

Changes in 2.0

An optional collation argument has been added.

Signature

Argument
Type
Meaning
value
xs:string?
The containing string
test
xs:string?
The test string
collation
(optional)
xs:string
Identifies the collation to be used for comparing strings.
Result
xs:string
A string containing those characters that follow the first occurrence of the test substring within the containing string

Effect

If the containing string (
value
) does not contain the
test
substring, the function returns a zero-length string. Note that this could also mean that the containing string ends with the
test
substring; the two cases can be distinguished by calling the
ends-with()
function.

If the
value
does contain the
test
substring, the function returns a string made up of all the characters that appear in
value
after the first occurrence of the
test
substring.

If either of the first two arguments is an empty sequence, it is treated as if it were a zero-length string.

If the
test
substring is zero-length, the function returns
value
.

If
value
is zero-length, the function returns a zero-length string.

If a
collation
is specified, this collation is used to test whether the strings match. See the description of the
contains()
function on page 730 for an account of how substring matching works with a collation. If the
collation
argument is omitted, the function uses the default collation.

Things get complicated if the collation classifies characters such as space or hyphen as ignorable for sorting purposes. If hyphen is ignorable, then
substring-after(“a-b-c”, “b-”)
returns
-c
. That's because the match chosen for
b-
is the minimal matching substring, which is
b
.

Other books

Man Enough For Me by Rhonda Bowen
Night Angel (Angel Haven) by Miller, Annette
Origin by Dan Brown
Airs & Graces by A.J. Downey, Jeffrey Cook
L8r, G8r by Lauren Myracle
The Joy of Pain by Smith, Richard H.
Amazon Challenge by Robin Roseau
The Heiress Bride by Catherine Coulter
Forever His by Shelly Thacker