Tải bản đầy đủ (.pdf) (60 trang)

Oracle XSQL combining sql oracle text xslt and java to publish dynamic web content phần 7 pptx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (764.36 KB, 60 trang )

xsl:include and xsl:import Syntax
These two elements share almost the exact same syntax:
<xsl:import href=”address” />
<xsl:include href=”address” />
The href attribute specifies the URI of the stylesheet that you wish to import or
include, respectively. They can be the children of the top-level element only, and they can
have no children. If they are used, they must be the first children of the root element.
Specifically, no child element of the root can precede xsl:import except xsl:include,
and no child element of the root can precede xsl:include except xsl:import.
xsl:apply-imports
This element is used to override the default behavior of XSLT concerning imported
stylesheets. By default, an imported stylesheet template is used only if there are no tem-
plates of the same name defined in the main stylesheet. With xsl:apply-imports,
you can specifically request that an imported template be applied from within a template
of the same name.
<xsl:apply-imports/>
This element can’t have children, and the only valid parent is xsl:template.
Sorting
XSLT gives you a mechanism for sorting data. Of course, you can also sort at the SQL
level. Generally speaking, it is more efficient to sort at the SQL level than at the XSLT
level. There will be cases, though, in which you will need to sort by using XSLT. This
section defines the syntax for the xsl:sort element and gives examples of it’s use.
xsl:sort Syntax
The xsl:sort element changes the default sorting. By default, elements are presented
in document order. However the elements are sequenced in the document in the order
in which they are output. The xsl:sort element allows the order to be changed to
some other kind of sorting, typically alphabetic or numeric and based on some prop-
erty of the elements to be sorted.
<xsl:sort
select = “sort_expression”
lang = “”


data-type = “text” | “number” | “other_processor_supported_type”
order = “ascending” | “descending”
case-order = “upper-first” | “lower-first” />
Table 13.31 lists the attributes.
340 Chapter 13
Table 13.31 xsl:sort Attributes
ATTRIBUTE NAME
select The expression that is evaluated for each node.
Results of evaluations determine sort order.
lang RFC 1766 language code for the language used in
determining order. The default is the system
language.
data-type When set to “number”, sorting is done numerically
(2 precedes 100). When set to “text”, sorting is
done alphanumerically (100 precedes 2). Any
other types must be supported by the XSLT
processor. The default is “text”.
order Determines the direction of the sort. The default is
“ascending”.
case-order Determines whether lowercase letters precede
uppercase letters or vice versa. Default is language-
dependent. In English, uppercase precedes
lowercase.
Examples
The most important thing to remember when using the xsl:sort element is that
numeric sorts aren’t the same as alphanumeric sorts. Since the number 1 precedes the
number 2, 1,000 will precede 2 in an alphanumeric sort. In the following example in
which a sort is done by salary, the data type is set to number. In a numeric sort, of
course, 1,000 follows 2. This sort is also a multiple key sort because two different sort
elements are specified.

<xsl:stylesheet
version=”1.0”
xmlns:xsl=” /><xsl:template match=”page”>
<html>
<head><title>Simple Stylesheet</title></head>
<body>
<h1>Simple Stylesheet</h1>
<table border=”0”>
<th></th><th>Name</th><th>Job</th><th>Salary</th>
<xsl:for-each select=”ROWSET/ROW”>
<xsl:sort select=”JOB”/>
<xsl:sort select=”SAL”
order=”descending”
data-type=”number”/>
XSLT In-Depth 341
<tr>
<td><xsl:value-of select=”@num”/></td>
<td><b><xsl:value-of select=”ENAME”/></b></td>
<td><xsl:value-of select=”JOB”/></td>
<td><xsl:value-of select=”SAL”/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Whitespace Handling
You can define how whitespace should be handled for elements by using the
xsl:preserve-whitespace and xsl:strip-whitespace elements. The

xsl:preserve-whitespace and xsl:strip-whitespace elements are closely
related and share essentially the same syntax. Both are top-level elements without chil-
dren, and both must be children of the root element.
<xsl:preserve-whitespace elements=”element_list” />
<xsl:strip-whitespace elements=”element_list” />
The elements attribute is set to a whitespace-delimited list of element names. For
xsl:preserve-whitespace, all whitespace between the start and end tags for
those elements is preserved. For the xsl:strip-whitespace, all whitespace
between the start and end tags for those elements is deleted.
Miscelleneous Elements
These last two elements don’t fit in particularly well anywhere else. The first,
xsl:key, defines search patterns for elements and is used in conjunction with the
key() function discussed later. The second, xsl:message, provides a way to send
messages to the XSLT processor, while the third is used with XSLT extensions.
xsl:key Syntax
The xsl:key element creates identifiers for elements. A key allows you to easily select
one or more elements based on the value of an attribute or the value of the element. It
is a top-level element that can be a child of the root element only, and it has no children.
342 Chapter 13
Table 13.32 xsl:key Attributes
ATTRIBUTE DESCRIPTION
Name The name for the key.
match The XPath pattern describing a set of elements to
match against.
use The expression describing an attribute or node of
target elements. Used by the key function to
evaluate whether or not an element should be
included in the return node set.
There may be more than one key element per stylesheet, but they should all have
unique names. A key is used in conjunction with the key() function.

<xsl:key
name = “key_name”
match = “nodeset_pattern”
use = “node_expression” />
Table 13.32 lists the attributes.
xsl:message
The xsl:message element method provides a mechanism to communicate messages
to the XSLT processor. What the XSLT processor does with these messages is processor-
dependent.
<xsl:message
terminate = “yes” | “no”>
message
</xsl:message>
If terminate is set to “yes”, the XSLT processor should stop processing. By
default, it is set to “no”.
xsl:fallback
The xsl:fallback element works with extension elements that aren’t defined in
XSLT 1.0. It defines what to do if an extension that you are trying to use is unknown or
unavailable to the XSLT processor.
<xsl:fallback>
Template XSLT
</xsl:fallback>
The xsl:fallback element should be an immediate child of the extension element
that might not be supported.
XSLT In-Depth 343
XPath
XPath is a language designed to locate nodes in an XML document. The simple paths
and expressions that you’ve used thus far are all examples of XPath in action. In many
cases, its syntax is similar to that used by file systems. This isn’t coincidental—both
XML documents and file systems are tree-based. However, XPath goes a bit beyond the

simple path notation you’ve seen so far. It has, for example, its own data types and
built-in functions. It also has a rich tool set of axes and predicates; the axes allow you
to navigate and grab nodes across the XML tree, and the predicates allow you to filter
the nodes that you grab.
This section covers XPath by looking first at the different data types that XPath sup-
ports. Then you’ll learn formally about expressions and paths, with which, from the
previous section, you already have experience. This section concludes with a discus-
sion of axes and predicates. The built-in functions are discussed in the final section of
this chapter.
Expressions and Data Types
XPath is a simple language, the key, omnipresent component of which is the expression.
An XPath expression is simply some combination of the XPath language elements—
operators, paths, variables, predicates, function calls, names, and/or literals. Basically,
any time that you write XPath you write an XPath expression.
An XPath expression is evaluated to a data type. XPath has four data types: node
sets, Booleans, numbers, and strings. They are collectively known as objects. Generally,
these types can interchange with one another—for instance, it’s not an error to pass a
node set to a string function. It just interprets the string value of the first node as a
string. Let’s look at each of these data types in detail.
A node set is one or more nodes. An XPath expression such as”ROWSET/ROW/*”
returns a node set. Any kind of expression that is meant to return a node set is called a
location path. Creating a location path is a lot of the work that you do in XPath, and it is
covered specifically in later sections of this chapter. The key to constructing good loca-
tion paths is to understand how to use the axes.
You may have noticed that there isn’t a data type for just a single node. This is by
design: instead of creating a separate data type, XPath keeps it simple by treating sin-
gle nodes and sets of node the same. Functions that expect to deal with a single node—
string() and number(), for example—simply take the first node in the node set. As
a developer, the burden is on you to make sure that the first node is the one that you
want processed.

The XPath number data type is generally used for pedestrian activities such as
counting the number of nodes in a node set. Though not a mathematically strong lan-
guage, XPath does give the ability to do the following mathematical operations:
■■
Addition (+)
■■ Subtraction (()
344 Chapter 13
■■
Multiplication (*)
■■
Division (div)
■■
Modulus (mod)
There are several other mathematical functions, covered later in this chapter, that you
can use.
XPath strings are composed of Unicode characters by default. Since XPath is a text-
focused language, a lot of the work that you do deals with strings. The core functions
include several string functions that give you a rich set of functionality. With a little
work, you can do a lot of parsing and chopping of strings.
An XPath boolean value is either true or false, and boolean expressions, covered
earlier when you learned about conditional processing, evaluate to either true or false.
Location Paths
A location path is an expression that returns a node set. Location paths make XPath
powerful, but they also make the language complex. A location path describes one or
more nodes, where a node is the root node, an element, an attribute, a comment, a
namespace declaration, a processing instruction or some text.
A location path can be either relative or absolute. It is absolute if it begins with a
‘/’. As with absolute file paths and URLs, an absolute location path starts at the top
of the tree. A relative path starts with the context node. Unlike with URLs embedded
in Web pages, there is no rule of thumb that says that you should always use relative

URLs. In many cases, you should use them, but absolute paths can be invaluable in
grabbing data from distant parts of the tree.
Any location path is composed of location steps. Location steps can have three
parts—an axis, a node test, and a predicate. They take the following form:
axis::node-test[predicate]
This form probably looks unfamiliar to you, and you may be unconvinced that this
was the same language that you were using earlier. A couple of explanations are in
order. First, the predicate isn’t required. Second, the child axis is the default axis, which
means that a statement such as:
ROWSET/ROW
translates to:
child::ROWSET/child::ROW
Following this syntax, ROWSET and ROW are node tests. A node test is a node name, the
element wildcard (*), the attribute wildcard (@*), or a node-test function. If a node
name is used, only nodes of that name are selected. If the element wildcard character is
used, any element will match, while the attribute wildcard will match only attribute
nodes. Table 13.33 lists the available node-test functions.
XSLT In-Depth 345
Table 13.33 Node-Test Functions
FUNCTION DESCRIPTION
node() Returns true on any type of node
comment() Returns true for comment nodes
Processing-instruction() Returns true for processing-
instruction nodes
Text() Returns true for text nodes
Unlike with file systems, the wildcard can be used to skip levels of the tree. The fol-
lowing location paths select, regardless of who the parent is, any grandchild of the con-
text node named ENAME.
*/ENAME
child::*/child::ENAME

The last piece in the puzzle is the predicate. The predicate, which is optional, is a
way to filter down the node set achieved by the axis and the node test. Ultimately, it is
a boolean expression much like those discussed earlier. If the expression is true, the
node will be included in the resultant node set. There is one twist, however. If a num-
ber is given in the predicate itself, it will not follow the rules set out earlier. Rather, it
will evaluate to true for that particular node in the node set. So the following location
path:
ROWSET/ROW[3]
actually translates to:
ROWSET/ROW[position()=3]
The position function is invoked on each ROW node, and only the third one will be
returned.
Axes
The XPath class is built around the concept of axes. You can think of an axis as a way
to define a relationship between two nodes. For any given two nodes and any given
axis, the two nodes are either both on the axis or not. Since XML describes trees, the
axes that XPath defines describe tree-based relationships. For instance, one popular
axis is the descendant axis of a particular node. Node B is on the descendant axis of
node A if it or any of its ancestors is a child of node A. Algorithmically, you can con-
sider the descendant axis this way:
346 Chapter 13
Figure 13.4 Descendant axis of a node.
1. Ask node B, “Who is your parent?”
2. Ask the parent, “Who is your parent?”
3. Continue until the answer is “node A” or you reach the root node.
4. If your algorithm stops on node A, node B would be node A’s descendant axis;
if your algorithm stops at the root node and the root node is not node A, node
B would not be the descendant’s axis.
If you are more of a visual thinker than an algorithmic thinker, Figure 13.4 illustrates
the same concept. All the nodes denoted with bold circles are on the descendant axis of

the node A.
This section covers all of the axes in XPath, starting with the most popular. A dia-
grams like Figure 13.4 is provided for each axis involving elements. Before moving on,
it’s important to make a couple of notes about the diagrams. This particular axis
includes the node from which the axis is defined. However, this is not always the case.
Thus, the reference element of the axis is delineated with a ring. A square inside the
ring means that the reference element is not a member of the axis. Additionally, there
are several axes—the sibling axes—that don’t follow the structural connections that
XML defines. Thus, the axes are defined with thick dotted lines, whereas the structure
is defined with solid lines.
self (.)
The self axis describes the reference element itself. It has (and always has) one mem-
ber only, the reference element. It can be abbreviated with the symbol “.” and is shown
in Figure 13.5.
XSLT In-Depth 347
Figure 13.5 Self axis.
descendant-or-self (//)
The descendant-or-self axis includes the reference element and all of its descen-
dants. It always has at least one element, the reference element. It can be abbreviated
with the”//”symbol and is shown in Figure 13.6.
parent ( )
The parent axis includes, at most, one element, the parent of the context element. If the
context element is the root element, this axis will be empty; otherwise, the axis will have
one member only. It can be abbreviated with the symbol and is shown in Figure 13.7.
Figure 13.6 Descendant-or-self axis.
348 Chapter 13
Figure 13.7 Parent axis.
attribute (@)
The attribute axis includes the attributes of the given element. As discussed earlier,
attributes are considered nodes. This is the one XPath axis that works with nonelement

nodes. It can be abbreviated with the “@” symbol.
child
The child axis, which may be empty, includes all the immediate children of the con-
text element. It doesn’t include the context element, as shown in Figure 13.8.
Figure 13.8 Child axis.
XSLT In-Depth 349
Figure 13.9 Descendant axis.
descendant
The descendant axis, which may be empty, includes all the descendants of the con-
text element but does not include the context element itself. For elements without chil-
dren elements, this axis will be empty, as shown in Figure 13.9.
ancestor
The ancestor axis, which may be empty, includes all the ancestors of the context ele-
ment but does not include the context element itself. This axis is empty for the root ele-
ment and has at least one member for all other elements, as shown in Figure 13.10.
Figure 13.10 Ancestor axis.
350 Chapter 13
Figure 13.11 Ancestor-or-self axis.
ancestor-or-self
The ancestor-or-self axis includes all of the ancestors of the context element and
the context element itself. It always has at least one member, the context element. All
elements except the root element will have at least two members on this axis, as shown
in Figure 13.11.
following-sibling
The following-sibling axis includes, at most, one element—the next sibling in
document order. If it exists, the only member of this axis is the next element with the
same parent. Figure 13.12 assumes that the elements on the left of the document pre-
cede the elements on the right.
Figure 13.12 Following-sibling.
XSLT In-Depth 351

preceding-sibling
The preceding-sibling axis includes, at most, one element—the previous sibling
in document order. If it exists, the only member of this axis is the first preceding ele-
ment with the same parent. Figure 13.13 assumes that the elements on the left of the
document precede the elements on the right.
following
The following axis, which might be empty, includes all elements that follow the context
element in the document. It does not include the context element, nor does it include
any ancestor of the context element.
preceding
The preceding axis which might be empty, includes all elements that precede the con-
text element in the document. It doesn’t include the context element.
namespace
The namespace axis includes all elements in the same namespace (as defined by
xmlns) as the context node. It will always include the context element, and it may
include nothing but the context element.
Figure 13.13 Preceding-sibling.
352 Chapter 13
XPath and XSLT Functions
The following functions can be used anywhere in a stylesheet. Most are defined as part
of XPath proper, while some were added solely for XSLT. The XSLT-specific functions are
covered first, followed by the node-set, string, boolean, and number functions.
XSLT Specific Functions
current
The current function returns the current node.
node-set current()
document
The document function returns one or more external documents as node sets.
node-set document(uri, base-uri)
node-set document(node-set_as_uri, node-set_as_base-uri)

Table 13.34 lists the parameters.
format-number
The format-number function converts a number to a string in accordance with the
specified format.
string format-number(num, format_str, decimal_format_name)
Table 13.35 lists the parameters.
Table 13.34 document Parameters
ARGUMENT DESCRIPTION
uri The URI of the external document.
base-uri The base URI used to resolve URIs found in the
external document.
node-set_as_uri A set of URIs for documents to load. The value of
each node is a URI.
node-set_as_base-uri A set of base URIs corresponding to the
documents listed in the first argument.
XSLT In-Depth 353
Table 13.35 format-number Parameters
ARGUMENT DESCRIPTION
num The number you wish to format.
format_str The format mask that should be used to format
string.
decimal_format_name Optional—the name of a decimal-format element
that describes how to format decimals.
generate-id
The generate-id function generates a unique identifier for a given node.
string generate-id(node_set_to_id)
string generate-id()
Table 13.36 lists the parameters.
The function will return a string that can be used as a valid XML name. The XSLT
processor must create different identifiers for each node in the document. On a partic-

ular transformation, the processor must produce the same id for the same node across
multiple calls to generate-id. However, the XSLT processor is not required to gen-
erate the same id for the same id across separate transformations.
key
The key function is used in conjunction with an xsl:key element to look up values
according to the algorithm that the key element describes and using the second
parameter as input.
node-set key(key_name,node_set_to_evaluate)
node-set key(key_name,string_value)
node-set key(key_name,object_value)
Table 13.37 lists the parameters.
Table 13.36 generate-id Parameters
ARGUMENT DESCRIPTION
node-set Optional—a node set in which only the first node is
evaluated. If the node set contains more than one
node, only a unique identifier will be generated for
the first node of the node set, as determined by
document order. If the argument is omitted, a
unique id is generated for the context node.
354 Chapter 13
Table 13.37 key Parameters
ARGUMENT DESCRIPTION
key_name Name of the xsl:key element to use.
node_set_to_evaluate Each node in the node set evaluated to a string. The
result is the node set that would be accumulated by
individually calling the key function on each string
node value for each node in the node set.
string_value The string used in the evaluation.
object_value The object translated to a string as if by a call to the
string() function. The effect is that of calling the

function with string_value as the second argument.
As you will recall from the earlier discussion on the xsl:key element, keys are a way
of defining a search in XSLT. When you set up the xsl:key element, all you have to do
is use the key function to get a set of values that you want to pass in a parameter. The key
function uses the following algorithm to determine the nodes that should be included in
the result, assuming a string is passed as the second parameter of the key function.
1. The value of the match attribute and the value of the use attribute of the
specified xsl:key element are retrieved.
2. The node set specified by the match value is loaded from the XML source
document.
3. The first node in the node set is pulled.
4. The use attribute is evaluated against the first node to produce a value.
5. The value is compared to the string passed to the key function.
6. If the two are equal, the node will be included in the result node set.
7. The previous four steps are repeated for each node in the node set.
8. The result node set is returned.
In the case where a set of nodes is passed to the key element, the foregoing algorithm
is repeated for the value of each node in the node set. The result is a set of unique nodes
produced by all the evaluations. In the case where some other object is passed to the
key function, it is translated to a string as if by the string function and then the same
algorithm is returned.
system-property
The system-property asks the XSLT processor to return a system property.
object system-property(property_name)
Table 13.38 lists the parameters.
XSLT In-Depth 355
Table 13.38 system-property Parameters
ARGUMENT DESCRIPTION
property_name The name of the property you desire.
There are only three properties that an XSLT processor is required to return:

xsl:vendor. The vendor that provides the XSLT processor.
xsl:vendor-url. The URL of the vendor.
xsl:version. The version of XSLT implemented by the XSLT processor.
A given XSLT processor may (or may not) return other properties.
unparsed-entity-uri
The unparsed-entity-uri returns an unparsed entity URI from the source docu-
ment type definition (DTD). If doesn’t exist, the empty string will be returned.
string unparsed-entity-uri(entity_name)
Table 13.39 lists the parameters.
Table 13.39 unparsed-entity-uri Parameters
ARGUMENT DESCRIPTION
entity_name The name of the entity that has the URI you desire.
Node-Set Functions
count
The count function returns the number of nodes contained in a node set.
number count(node_set_to_count)
Table 13.40 lists the parameters.
356 Chapter 13
Table 13.40 count Parameters
ARGUMENT DESCRIPTION
node_set_to_count The node set that you wish to count.
id
The id function selects an element by its unique XML id.
node-set id(string_list_of_ids)
node-set id(node_set_to_evaluate)
node-set id(object_to_evaluate)
Table 13.41 lists the parameters. The id for the nodes is specified by the source XML
DTD. If the DTD doesn’t exist or doesn’t specify a default, no nodes will be returned.
last
The last function returns the size of a node set. When used in a predicate, the size of

the predicate’s node set is returned. When used by itself, the size of the context
node-set is returned.
number last()
Table 13.41 id Parameters
ARGUMENT DESCRIPTION
String_list_of_ids A whitespace-delimited list of ids.
Node_set_to_evaluate A set of nodes in which the values are evaluated
as a list of ids.
Object_to_evaluate An object that is converted to a string as if by a call
to the string function and then read as a
whitespace-delimited list of ids.
XSLT In-Depth 357
local-name
The local-name function returns the local name of a node—the name without any
namespace prefixes.
string local-name()
string local-name(node_set_to_evaluate)
If node_set_to_evaluate has more than one node, only the first node in
document order will be processed. If no argument is passed, the context node will be
evaluated.
Name
The name function returns the fully qualified name of a node, including any name-
space prefix.
string local-name (node_set_to_evaluate)
string local-name ()
If node_set_to_evaluate has more than one node, only the first node in document
order will be processed. If no argument is passed, the context node will be evaluated.
namespace-uri
The namespace-uri function returns the namespace URI of a node.
string namespace-uri (node_set_to_evaluate)

string namespace-uri ()
If node_set_to_evaluate has more than one node, only the first node in
document order will be processed. If no argument is passed, the context node will be
evaluated.
position
The position function returns the position of the context node within the current
context.
number position()
358 Chapter 13
String Functions
concat
The concat function concatenates the argument strings.
string concat(string1, string2, string3 . . .)
At least two arguments are required.
contains
The contains function determines whether a string contains a substring.
boolean contains(superstring, substring)
normalize-space
The normalize-space function strips a string of leading and trailing whitespace and
replaces any sequences of whitespace characters with a single whitespace character.
string normalize-space(string_to_normalize)
string normalize-space()
If the argument is omitted, the context node will be converted to a string.
starts-with
The starts-with function returns true if a string starts with a given string.
boolean starts-with(superstring, prefixstring)
Table 13.42 lists the parameters.
Table 13.42 starts-with Parameters
ARGUMENT DESCRIPTION
superstring The target string.

prefixstring The prefix string that the target string may or may
not start with.
XSLT In-Depth 359
string
The string function converts an object to a string.
string string(node_set_to_convert)
string string(number_to_convert)
string string(boolean_to_convert)
string string(string_to_convert)
string string(object_to_convert)
string string()
Table 13.43 lists the parameters.
string-length
The string-length function returns the number of characters in a string.
number string-length(target_string)
number string-length()
If a string is passed to the function, its length will be returned; otherwise, the string
value of the context node is returned.
Table 13.43 string Parameters
ARGUMENT DESCRIPTION
node_set_to_convert The string value is returned to the first node in
document order of the node set.
number_to_convert A number is converted as normal, with the
following exceptions: an infinite number, which is
returned as the string “Infinity” or
“–Infinity”, and “not a number”, which is
returned as “NaN”.
boolean_to_convert If true, the string “true” is returned. If false, the
string “false” is returned.
string_to_convert If a string is passed, it will be returned without

modification.
object_to_convert If some other type of object is passed, its
conversion will be object-dependent and not
defined by XPath.
360 Chapter 13
Substring
The substring function returns a substring of a string.
string substring(superstring, beginning_pos, end_pos)
string substring(superstring, beginning_pos)
Table 13.44 lists the arguments.
The numbering of characters is different than it is in Java and ECMAScript, where
the position of the first character is 0. For this function, the first character is at position
1 and the last character’s position is equivalent to the length of the string. If you pass 0
as the second argument, it will resolve as 1. If you pass a noninteger, it will be rounded
to an integer and the integer will be evaluated. The function will return the empty
string if the arguments don’t make sense, because the third argument is less than the
second argument, an argument is negative, an argument is infinity, or an argument is
NotANumber.
substring-before
The substring-before function returns a substring of a string that precedes a given
token. It can be used to tokenize a string based on a delimiter.
string substring-before(superstring, delimiter_string)
Table 13.45 lists the arguments.
If the superstring doesn’t contain the delimiter_string, the empty string will be
returned. The delimiter will not be included in the returned string.
Table 13.44 Substring Arguments
ARGUMENT DESCRIPTION
superstring The string from which the substring is pulled.
beginning_pos The position of the first character of the substring,
where the first character is numbered as 1.

end_pos If present, the position of the last character of the
desired substring. If not present, the last character
of the substring is the last character of the
superstring.
XSLT In-Depth 361
Table 13.45 Substring-before Arguments
ARGUMENT DESCRIPTION
superstring The string from which the substring is pulled.
delimiter_string The delimiter that should mark the end of the
substring that you desire.
substring-after
The substring-after function returns a substring of a string that follows a given
token. It can be used to tokenize a string based on a delimiter.
string substring-after(superstring, delimiter_string)
Table 13.46 lists the arguments.
If the superstring doesn’t contain the delimiter_string, the empty string will be
returned. The delimiter will not be included in the returned string.
translate
The translate function translates the target_string by interchanging characters
of the base_string with characters of the source_string. The function can also be
used to remove characters from the target_string.
string translate(target_string, base_string, source_string)
Table 13.47 lists the arguments.
Each character in the base_string that has a character in the source_string at
the same position is replaced in the target_string. If the source_string is
shorter than the base_string (or empty), the trailing characters (or all the characters)
in the base_string are eliminated from the target_string.
Table 13.46 Substring-after Arguments
ARGUMENT DESCRIPTION
superstring The string from which the substring is pulled.

delimiter_string The delimiter that should precede the substring
that you desire.
362 Chapter 13
Table 13.47 translate Arguments
ARGUMENT DESCRIPTION
target_string The string to be translated.
base_string The base_string, which contains the list of
characters that should be translated.
source_string The source_string, which is the source of
characters that should replace the base-string
characters.
boolean Functions
The following functions return true and false. They have theoretical importance, but
probably the only one you will regularly use is the not function.
boolean
The boolean function returns a boolean value based on the argument
boolean boolean(node-set)
boolean boolean(string)
boolean boolean(number)
boolean boolean(boolean)
boolean boolean(object)
Table 13.48 lists the arguments.
Table 13.48 boolean Arguments
ARGUMENT DESCRIPTION
node-set True if the node set is not empty.
string True if the length is greater than 0.
number True if it isn’t 0 or NotANumber.
boolean True if true.
object The boolean value of objects of a type other than
the basic type is dependent on that type and isn’t

defined by XPath.
XSLT In-Depth 363
false
The false function returns false.
boolean false()
lang
The lang function determines whether a particular lang is the language or whether a
sublanguage specified by the argument is the same as the context node.
boolean lang(lang_string)
The lang value of the context node is determined by the xml:lang attribute of the
context node or the xml:lang attribute of the nearest ancestor that has an xml:lang
attribute. If no xml:lang attribute can be found, the function returns false.
not
The not function inverses the boolean value of its argument. True returns false and
false returns true.
boolean not(boolean_value)
true
The true function returns true.
boolean true()
Number Functions
ceiling
The ceiling function returns the next highest integer compared to the number
_argument or the number_argument itself if it is an integer.
number ceiling(number_argument)
floor
The floor function returns the next-lowest integer compared to the number_argument
or the number_argument itself if it is an integer.
364 Chapter 13

×