Name
contains()
Determines whether the first argument string contains the second.
Syntax
[1.0] booleancontains(
string
,string
)
[2.0] xs:booleancontains(
xs:string?
,xs:string?
)
[2.0] xs:booleancontains(
xs:string?
,xs:string?
,$collation as xs:string
)
Inputs
Two strings. If the first string contains the second string,
the function returns the boolean value true
. [2.0] In XSLT
2.0, there is an optional third argument—the name of a collation
that specifies how strings in different languages are
compared.
Output
The boolean value true
if
the first argument contains the second; false
otherwise. If the second string is
a zero-length string, contains()
returns true
. If the first string is a
zero-length string, contains()
returns false
.
Defined in
[1.0] XPath section 4.2, “String Functions.”
[2.0] XQuery 1.0 and XPath 2.0 Functions and Operators section 7.5, “Functions Based on Substring Matching.”
Example
This stylesheet uses the replace-substring
named template. It
passes three arguments to the replace-substring
template: the original
string, the substring to be searched for in the original string,
and the substring to replace the target substring in the original
string. The replace-substring
template uses the contains()
, substring-after()
, and substring-before()
functions.
Here is our sample stylesheet. It replaces all occurrences
of World
with the string
"Mundo"
:
<?xml version="1.0"?>
<!-- contains1.xsl --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output ...
Get XSLT, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.