<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://commons.oreilly.com/wiki/skins/common/feed.css?97"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>XPath and XPointer/XPath Functions and Numeric Operators - Revision history</title>
		<link>http://commons.oreilly.com/wiki/index.php?title=XPath_and_XPointer/XPath_Functions_and_Numeric_Operators&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.11.0</generator>
		<lastBuildDate>Thu, 23 May 2013 03:56:21 GMT</lastBuildDate>
		<item>
			<title>Docbook2Wiki: Initial conversion from Docbook</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=XPath_and_XPointer/XPath_Functions_and_Numeric_Operators&amp;diff=5168&amp;oldid=prev</link>
			<description>&lt;p&gt;Initial conversion from Docbook&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 09:53, 7 March 2008&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;</description>
			<pubDate>Fri, 07 Mar 2008 09:53:46 GMT</pubDate>			<dc:creator>Docbook2Wiki</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:XPath_and_XPointer/XPath_Functions_and_Numeric_Operators</comments>		</item>
		<item>
			<title>Docbook2Wiki: Initial conversion from Docbook</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=XPath_and_XPointer/XPath_Functions_and_Numeric_Operators&amp;diff=5107&amp;oldid=prev</link>
			<description>&lt;p&gt;Initial conversion from Docbook&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 09:50, 7 March 2008&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;</description>
			<pubDate>Fri, 07 Mar 2008 09:50:41 GMT</pubDate>			<dc:creator>Docbook2Wiki</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:XPath_and_XPointer/XPath_Functions_and_Numeric_Operators</comments>		</item>
		<item>
			<title>Docbook2Wiki: Initial conversion from Docbook</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=XPath_and_XPointer/XPath_Functions_and_Numeric_Operators&amp;diff=5046&amp;oldid=prev</link>
			<description>&lt;p&gt;Initial conversion from Docbook&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{XPath and XPointer/TOC}}&lt;br /&gt;
The XPath 1.0 Recommendation specifies a number of ''functions'' and ''numeric operations'' that can be used to refine the results returned by an XPath expression.&lt;br /&gt;
&lt;br /&gt;
Before getting into the details of these features' uses, let's take a look at a fundamental question: what are functions in the first place? (If you're already familiar with the use of functions in programming languages, such as Java, C++, and Visual Basic, feel free to skip this section.)&lt;br /&gt;
&lt;br /&gt;
== Introduction to Functions ==&lt;br /&gt;
&lt;br /&gt;
When I was a kid, I loved watching my father work on cars. He'd been a mechanic all his life, and the automotive toolkit he'd acquired over the course of the years was exotic (to my eyes, anyhow).&lt;br /&gt;
&lt;br /&gt;
One of the smaller items in Dad's toolkit was something he called a &amp;quot;spark-plug gapper.&amp;quot; It was something like a Swiss-Army knife, with a half-dozen or so stiff steel prongs that you could swivel out from the tool's main body. Each L-shaped prong was of a slightly different thickness; depending on the model of car you were working on and the specific spark plug's specifications, you'd tap the end of the spark plug on the pavement and, using the gapper, ensure that the distance across which the spark was to jump was just right. There was also a small, stiff plane of sheet metal attached to the gapper, which you could use to spread the gap if you'd already closed it up too much. The objective was the get the gap just right, to ensure that the spark plug fired in just exactly the right way.&lt;br /&gt;
&lt;br /&gt;
A function in computer-language terms is like a spark-plug gapper. It's a tool provided by a software developer. You use the tool in the same general way for a given task, whenever you need to obtain some result you can't obtain (or obtain easily) without the tool.&lt;br /&gt;
&lt;br /&gt;
Almost without exception, regardless of the computer language in question, functions are represented syntactically the same way:&lt;br /&gt;
&lt;br /&gt;
 function_name(arg1, ...)&lt;br /&gt;
&lt;br /&gt;
Each function (like each tool in a mechanic's toolbox) has a distinct name. Depending on the function, you may pass one or more arguments to it, which change its behavior in various ways. The arguments are enclosed in parentheses. Thus, the spark-plug gapper might be represented like this:&lt;br /&gt;
&lt;br /&gt;
 gapper(prong)&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;tt&amp;gt;gapper&amp;lt;/tt&amp;gt; is the function name and &amp;lt;tt&amp;gt;prong&amp;lt;/tt&amp;gt;, a single argument provided (or &amp;quot;passed&amp;quot;) to the function. Under many circumstances, you wouldn't pass a function like this the literal token &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;r&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;o&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;g&amp;lt;/tt&amp;gt;; rather, this is just a placeholder, a reminder to you of what you do pass to it. In this form, the function syntax is called a ''prototype''. When you actually use (or &amp;quot;call&amp;quot; or &amp;quot;invoke&amp;quot;) a function, you typically substitute a literal value for each argument. So an actual call to our hypothetical &amp;lt;tt&amp;gt;gapper( )&amp;lt;/tt&amp;gt; function might look like this:&lt;br /&gt;
&lt;br /&gt;
 gapper(1)&lt;br /&gt;
&lt;br /&gt;
Now, many functions are fussy about both the number of arguments and the type. Depending on how the &amp;lt;tt&amp;gt;gapper( )&amp;lt;/tt&amp;gt; function is written, for example, the following might be illegal calls to it:&lt;br /&gt;
&lt;br /&gt;
 gapper(3, 6)&lt;br /&gt;
 gapper(&amp;quot;1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
In the first example, there's more than one argument passed; in the second, the argument being passed is a literal string rather than a literal number. If in fact a legal call to &amp;lt;tt&amp;gt;gapper( )&amp;lt;/tt&amp;gt; passes only a single numeric argument, either of these two calls will fail — probably resulting in an error message of some kind.&lt;br /&gt;
&lt;br /&gt;
=== What Functions Do ===&lt;br /&gt;
&lt;br /&gt;
The interesting thing about functions is that a call to one of them takes the place of some literal value in a &amp;quot;sentence&amp;quot; in the programming language in question. That is, a function ''returns a value''.&lt;br /&gt;
&lt;br /&gt;
So Dad, in my case, might say to me something like, &amp;quot;Here. Set the gap on this plug to fifteen-thousandths of an inch.&amp;quot; This would require me to know how to determine which prong on the gapper produced exactly that effect. More likely, especially if this was my first time handling the tool, he'd say, &amp;quot;Set the gap on this plug with prong number one&amp;quot; (or whatever). In a hypothetical computer language to achieve this purpose, this English-language instruction might be rendered:&lt;br /&gt;
&lt;br /&gt;
 setgap '''gapper(1)'''&lt;br /&gt;
             &lt;br /&gt;
&lt;br /&gt;
This would achieve the same effect as:&lt;br /&gt;
&lt;br /&gt;
 setgap '''.015'''&lt;br /&gt;
             &lt;br /&gt;
&lt;br /&gt;
That is, in formal terms, the &amp;lt;tt&amp;gt;gapper( )&amp;lt;/tt&amp;gt; function, when passed a numeric value of 1, returns the numeric value .015.&lt;br /&gt;
&lt;br /&gt;
=== Functions Within Functions ===&lt;br /&gt;
&lt;br /&gt;
Given, then, that a function returns a value and that the arguments passed to functions are themselves values, it's entirely legal — even desirable, in many circumstances — to pass one function as an argument to another.&lt;br /&gt;
&lt;br /&gt;
Returning to the spark plug-gapping tool, as you can see from the preceding example, the &amp;lt;tt&amp;gt;gapper( )&amp;lt;/tt&amp;gt; function returns a value in the form of a fraction of an inch, based on the &amp;quot;prong number&amp;quot; selected. This was eminently reasonable back in Dad's day. Now, though, most spark-plug gaps are expressed in terms of millimeters. So now we'd need a separate method for gapping a plug in metric units instead. The hypothetical computer-language expression of this might look something like:&lt;br /&gt;
&lt;br /&gt;
 setgap_mm inches_to_mm('''gapper(1)''')&lt;br /&gt;
&lt;br /&gt;
which is equivalent to:&lt;br /&gt;
&lt;br /&gt;
 setgap_mm inches_to_mm('''.015''')&lt;br /&gt;
&lt;br /&gt;
which in turn is equivalent to:&lt;br /&gt;
&lt;br /&gt;
 setgap_mm '''.38'''&lt;br /&gt;
             &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;gapper( )&amp;lt;/tt&amp;gt; function here still returns .015 — the value in inches of feeler #1's thickness. This value in turn is passed to a hypothetical conversion function, &amp;lt;tt&amp;gt;inches_to_mm( )&amp;lt;/tt&amp;gt;, which takes a single argument — a number of inches — and converts it to millimeters.&lt;br /&gt;
&lt;br /&gt;
== XPath Function Types ==&lt;br /&gt;
&lt;br /&gt;
The functions available for use in XPath expressions are categorized by the type of value they return and/or by the type of values they operate on as arguments. These categories are node-set, string, Boolean, and numeric functions.&lt;br /&gt;
&lt;br /&gt;
In each of the function prototypes in this section, I'll use the following scheme to denote the kind of arguments passed:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;string&amp;lt;/tt&amp;gt;&lt;br /&gt;
: Argument is a string value, to be enclosed in quotation marks in the function call. If a function call takes more than one string argument, I'll append a number to each, as in &amp;lt;tt&amp;gt;string1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt;, and so on.&lt;br /&gt;
;&amp;lt;tt&amp;gt;nodeset&amp;lt;/tt&amp;gt;&lt;br /&gt;
: Argument is a node-set, represented by an XPath location path. Note that if you're using XPath in an XSLT stylesheet, this location path will (if it's a relative path) be sensitive to the context established by the stylesheet at that point. Whether you're using XPath in XSLT or an XPointer, earlier portions of a complete location path can of course establish a context for node-set references in later portions.&lt;br /&gt;
;&amp;lt;tt&amp;gt;boolean&amp;lt;/tt&amp;gt;&lt;br /&gt;
: Argument has a Boolean value of true or false.&lt;br /&gt;
;&amp;lt;tt&amp;gt;number&amp;lt;/tt&amp;gt;&lt;br /&gt;
: Argument has a numeric value. If a function call takes more than one numeric argument, I'll append a number to each, as in &amp;lt;tt&amp;gt;number1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;number2&amp;lt;/tt&amp;gt;, and so on.&lt;br /&gt;
;&amp;lt;tt&amp;gt;anytype&amp;lt;/tt&amp;gt;&lt;br /&gt;
: Argument can be any of several types. For instance, you can pass certain functions a string or a numeric argument, and the function will handle any necessary data-type conversion.&lt;br /&gt;
;&amp;lt;tt&amp;gt;?&amp;lt;/tt&amp;gt;&lt;br /&gt;
: A question mark appended to one of the above data types means the argument is optional. For instance, a call to a hypothetical &amp;lt;tt&amp;gt;my_func( )&amp;lt;/tt&amp;gt; function might come with a prototype such as &amp;lt;tt&amp;gt;my_func(string?)&amp;lt;/tt&amp;gt;. This would mean that when you call &amp;lt;tt&amp;gt;my_func( )&amp;lt;/tt&amp;gt;, you may supply a string argument or no argument at all. In such a case, the function will usually assume some default value for the argument, perhaps derived from the context node at the point of the function call.&lt;br /&gt;
&lt;br /&gt;
Note that the type of data returned by each function is documented in a table at the start of the section dealing with the appropriate function type. Unlike functions in some traditional programming languages, XPath functions ''always'' return a value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
XSLT and EXSLT both provide functions that go beyond XPath itself. If you need something beyond what this chapter describes, see [[XPath and XPointer/Extension Functions for XPath in XSLT|Appendix A]].&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Node-Set Functions ===&lt;br /&gt;
&lt;br /&gt;
A node-set function, as the name implies, operates on a node-set; one of these functions also ''returns'' a node-set. [[XPath and XPointer/XPath Functions and Numeric Operators#xpathpointer-CHP-4-TABLE-1|Table 4-1]] summarizes the functions in this category. Each function is discussed in detail in a separate subsection following the table. These discussions assume that the source document being referenced by XPath expressions is the following fragment of an XML document:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;!DOCTYPE book:book &lt;br /&gt;
&amp;lt;!ATTLIST book:section id ID #IMPLIED&amp;gt;&lt;br /&gt;
]&amp;gt;&lt;br /&gt;
&amp;lt;book:book &lt;br /&gt;
   xmlns:book=&amp;quot;http://mynamespace/uri&amp;quot;&lt;br /&gt;
   xmlns:xlink=&amp;quot;http://www.w3.org/1999/xlink/ &amp;quot;&lt;br /&gt;
   xmlns=&amp;quot;http://www.w3.org/2000/svg&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
   &amp;lt;book:chapter&amp;gt;&lt;br /&gt;
      &amp;lt;book:section id=&amp;quot;sect_01&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;book:para id=&amp;quot;para_01&amp;quot;&amp;gt;Some text...&lt;br /&gt;
            For more information, see:&lt;br /&gt;
            &amp;lt;book:ref xlink:href=&amp;quot;crossref_01.xml&amp;quot;&amp;gt;crossref_01.xml&amp;lt;/book:ref&amp;gt;&lt;br /&gt;
         &amp;lt;/book:para&amp;gt;&lt;br /&gt;
         &amp;lt;svg&amp;gt;&lt;br /&gt;
            &amp;lt;circle style=&amp;quot;fill:yellow&amp;quot;&lt;br /&gt;
               cx=&amp;quot;100&amp;quot; cy=&amp;quot;100&amp;quot; r=&amp;quot;50&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;/svg&amp;gt;&lt;br /&gt;
      &amp;lt;/book:section&amp;gt;&lt;br /&gt;
   &amp;lt;/book:chapter&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
   [...remainder of book...]&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;/book:book&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
Note the &amp;lt;tt&amp;gt;ATTLIST&amp;lt;/tt&amp;gt; declaration in this document's prolog. As you'll see, your documents may need such a declaration (in either the internal DTD subset, as here, or an external one) to determine that an attribute is of the &amp;lt;tt&amp;gt;ID&amp;lt;/tt&amp;gt; type. However, if you're using the MSXML XSLT processor, be aware that the &amp;lt;tt&amp;gt;ATTLIST&amp;lt;/tt&amp;gt; declaration alone will not suffice to make the processor recognize the (in this case) &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; attribute; the processor also requires that the attribute's parent ''element'' (&amp;lt;tt&amp;gt;book:section&amp;lt;/tt&amp;gt;, here) be declared.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;xpathpointer-CHP-4-TABLE-1&amp;quot;&amp;gt;&lt;br /&gt;
'''Table 4-1. Node-set functions'''&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Function prototype !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 last(  )&lt;br /&gt;
| Number || Returns the number of nodes in the context node-set&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 position(  )&lt;br /&gt;
| Number || Returns the ordinal position of the context node within the context node-set&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 count(nodeset)&lt;br /&gt;
| Number || Returns the number of nodes in &amp;lt;tt&amp;gt;nodeset&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 id(string)&lt;br /&gt;
| Node-set || Returns the element node with an ID-type attribute equal to the value of the passed argument&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 local-name(nodeset?)&lt;br /&gt;
| String || Returns the local name (that is, the QName without a namespace prefix) of the first node in &amp;lt;tt&amp;gt;nodeset&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 namespace-uri(nodeset?)&lt;br /&gt;
| String || Returns the URI associated with the namespace prefix of the first node in &amp;lt;tt&amp;gt;nodeset&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 name(nodeset?)&lt;br /&gt;
| String || Returns the QName of the first node in &amp;lt;tt&amp;gt;nodeset&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== last( ) ====&lt;br /&gt;
&lt;br /&gt;
If the context node-set, at the point of the call to &amp;lt;tt&amp;gt;last( )&amp;lt;/tt&amp;gt;, contains 12 nodes, &amp;lt;tt&amp;gt;last( )&amp;lt;/tt&amp;gt; returns 12.&lt;br /&gt;
&lt;br /&gt;
Assume the context for the call to &amp;lt;tt&amp;gt;last( )&amp;lt;/tt&amp;gt; is established by a location path such as the following, referencing the sample XML document above:&lt;br /&gt;
&lt;br /&gt;
 //book:section/*&lt;br /&gt;
&lt;br /&gt;
This locates a node-set consisting of two element nodes, &amp;lt;tt&amp;gt;book:para&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;svg&amp;lt;/tt&amp;gt;. Therefore, a call to &amp;lt;tt&amp;gt;last( )&amp;lt;/tt&amp;gt; at this point returns the value 2.&lt;br /&gt;
&lt;br /&gt;
Probably the most common use of &amp;lt;tt&amp;gt;last( )&amp;lt;/tt&amp;gt; is in a location step's predicate, as in:&lt;br /&gt;
&lt;br /&gt;
 /book:book/book:chapter['''last(  )''']&lt;br /&gt;
&lt;br /&gt;
which selects the last chapter in the book.&lt;br /&gt;
&lt;br /&gt;
==== position( ) ====&lt;br /&gt;
&lt;br /&gt;
This commonly used function returns the integer representing the context node's ordinal position within the context node-set. These positions begin at 1 (for the first node in the node-set) and increment up to the value of the &amp;lt;tt&amp;gt;last( )&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
The sample XML document's root element, &amp;lt;tt&amp;gt;book:book&amp;lt;/tt&amp;gt;, has six element nodes visible along its &amp;lt;tt&amp;gt;descendant&amp;lt;/tt&amp;gt;:: axis (&amp;lt;tt&amp;gt;book:chapter&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;book:section&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;book:para&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;book:ref&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;svg&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;circle&amp;lt;/tt&amp;gt;). Therefore, this location path:&lt;br /&gt;
&lt;br /&gt;
 /book:book/descendant::*&lt;br /&gt;
&lt;br /&gt;
locates a node-set consisting of those six element nodes. You could locate just the &amp;lt;tt&amp;gt;svg&amp;lt;/tt&amp;gt; node by adding a predicate, as here:&lt;br /&gt;
&lt;br /&gt;
 /book:book/descendant::*[position(  )=5]&lt;br /&gt;
&lt;br /&gt;
That is, &amp;quot;locate the fifth node in the node-set.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Note that the value returned by the &amp;lt;tt&amp;gt;position( )&amp;lt;/tt&amp;gt; function is sensitive to the forward or reverse direction of the axis in effect. For forward-type axes, such as &amp;lt;tt&amp;gt;descendant::&amp;lt;/tt&amp;gt; in the preceding example, nodes are accessed in their natural document order; for reverse-type axes, nodes are accessed in reverse document order. So we could build a location path beginning, say, at the &amp;lt;tt&amp;gt;svg&amp;lt;/tt&amp;gt; element node and locating the ancestor &amp;lt;tt&amp;gt;book:chapter&amp;lt;/tt&amp;gt; element with a location path such as:&lt;br /&gt;
&lt;br /&gt;
 //svg/ancestor::*[position(  )=2]&lt;br /&gt;
&lt;br /&gt;
Here, the &amp;lt;tt&amp;gt;book:section&amp;lt;/tt&amp;gt; element is ancestor #1 in reverse document order, and &amp;lt;tt&amp;gt;book:chapter&amp;lt;/tt&amp;gt; is ancestor #2.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;position( )&amp;lt;/tt&amp;gt; function is important, as I've said, for two reasons:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;It can be represented in a location step's predicate simply by the value of the position for which you want to test. That is:&lt;br /&gt;
&lt;br /&gt;
 //svg/ancestor::*['''position(  )=2''']&lt;br /&gt;
&lt;br /&gt;
and:&lt;br /&gt;
&lt;br /&gt;
 //svg/ancestor::*['''2''']&lt;br /&gt;
&lt;br /&gt;
are functionally identical.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Many XSLT operations must be performed for every ''n''th occurrence of some kind of node in the source tree being transformed. For a simple example, perhaps you want to shade every odd row of a table, leaving the even rows unshaded: in other words, to shade every second row. This kind of processing can be achieved easily using &amp;lt;tt&amp;gt;position( )&amp;lt;/tt&amp;gt; together with the &amp;lt;tt&amp;gt;mod&amp;lt;/tt&amp;gt; numeric operator. I'll describe &amp;lt;tt&amp;gt;mod&amp;lt;/tt&amp;gt; later in this chapter and give an example of its use with &amp;lt;tt&amp;gt;position( )&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== count(nodeset) ====&lt;br /&gt;
&lt;br /&gt;
In every respect but one, the &amp;lt;tt&amp;gt;count( )&amp;lt;/tt&amp;gt; function operates identically to the &amp;lt;tt&amp;gt;last( )&amp;lt;/tt&amp;gt; function covered earlier. What makes it different is that &amp;lt;tt&amp;gt;count( )&amp;lt;/tt&amp;gt; takes one argument; &amp;lt;tt&amp;gt;last( )&amp;lt;/tt&amp;gt;, none. Thus, &amp;lt;tt&amp;gt;count( )&amp;lt;/tt&amp;gt; can be used to return the number of nodes in some arbitrary node-set other than the current one.&lt;br /&gt;
&lt;br /&gt;
The following XSLT template displays the number of the current section in the chapter within which it appears, then displays (using &amp;lt;tt&amp;gt;count( )&amp;lt;/tt&amp;gt;) the total number of &amp;lt;tt&amp;gt;book:section&amp;lt;/tt&amp;gt; nodes in the document as a whole. Note the nested &amp;lt;tt&amp;gt;xsl:for-each&amp;lt;/tt&amp;gt; elements, which cause processing in the template rule to &amp;quot;loop&amp;quot; through some set of operations for every node in a select node-set. Here, the outermost &amp;lt;tt&amp;gt;xsl:for-each&amp;lt;/tt&amp;gt; element loops through every &amp;lt;tt&amp;gt;book:chapter&amp;lt;/tt&amp;gt; element; the innermost &amp;lt;tt&amp;gt;xsl:for-each&amp;lt;/tt&amp;gt; element loops through each &amp;lt;tt&amp;gt;book:section&amp;lt;/tt&amp;gt; child of the selected &amp;lt;tt&amp;gt;book:chapter&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;xsl:template match=&amp;quot;/&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:for-each select=&amp;quot;book:book/book:chapter&amp;quot;&amp;gt;&lt;br /&gt;
       Chapter &amp;lt;xsl:value-of select=&amp;quot;position(  )&amp;quot;/&amp;gt;:&lt;br /&gt;
          &amp;lt;xsl:for-each select=&amp;quot;book:section&amp;quot;&amp;gt;&lt;br /&gt;
             This is section #&amp;lt;xsl:value-of select=&amp;quot;position(  )&amp;quot;/&amp;gt; of&lt;br /&gt;
             &amp;lt;xsl:value-of select=&amp;quot;'''last(  )'''&amp;quot;/&amp;gt; within its chapter.&lt;br /&gt;
          &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;
    The total number of sections in the book is: &amp;lt;xsl:value-of&lt;br /&gt;
      select=&amp;quot;'''count(//book:section)'''&amp;quot;/&amp;gt;&lt;br /&gt;
 &amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you apply this template to a sample document consisting of three &amp;lt;tt&amp;gt;book:chapter&amp;lt;/tt&amp;gt; elements — the first with one &amp;lt;tt&amp;gt;book:section&amp;lt;/tt&amp;gt; child elements, the second with three, and the third with two — the result is:&lt;br /&gt;
&lt;br /&gt;
    Chapter 1:&lt;br /&gt;
       &lt;br /&gt;
          This is section #1 of&lt;br /&gt;
          1 within its chapter.&lt;br /&gt;
       &lt;br /&gt;
    Chapter 2:&lt;br /&gt;
       &lt;br /&gt;
          This is section #1 of&lt;br /&gt;
          3 within its chapter.&lt;br /&gt;
       &lt;br /&gt;
          This is section #2 of&lt;br /&gt;
          3 within its chapter.&lt;br /&gt;
       &lt;br /&gt;
          This is section #3 of&lt;br /&gt;
          3 within its chapter.&lt;br /&gt;
       &lt;br /&gt;
    Chapter 3:&lt;br /&gt;
       &lt;br /&gt;
          This is section #1 of&lt;br /&gt;
          2 within its chapter.&lt;br /&gt;
       &lt;br /&gt;
          This is section #2 of&lt;br /&gt;
          2 within its chapter.&lt;br /&gt;
       &lt;br /&gt;
 The total number of sections in the whole book is: 6&lt;br /&gt;
&lt;br /&gt;
==== id(anytype) ====&lt;br /&gt;
&lt;br /&gt;
Unlike the other functions in the node-set category, the &amp;lt;tt&amp;gt;id( )&amp;lt;/tt&amp;gt; function actually returns a node-set, given its argument. (The argument is usually, but not always, a string; see [[XPath and XPointer/XPath Functions and Numeric Operators#id( ) and node-set arguments|Section 4.2.1.5]], for more information.) The value of the argument locates the set of all element nodes with the indicated ID-type attribute; because the value of an ID-type attribute, by definition, must be unique within a given document, the resulting node-set thus will contain a single element node (or be empty, if no elements have an ID-type attribute with this value). You can also use a whitespace-delimited ''list'' of values to return all element nodes with any matching ID-type attributes. For instance:&lt;br /&gt;
&lt;br /&gt;
 id(&amp;quot;sect_01 sect_05 sect_88&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
returns a node-set consisting of up to three element nodes. If no element nodes match a particular value, no error condition exists. In this example, if no element node has an ID-type attribute whose value is &amp;lt;tt&amp;gt;sect_05&amp;lt;/tt&amp;gt; but there ''are'' matches for the other two values, the resulting node-set would contain two elements.&lt;br /&gt;
&lt;br /&gt;
It's important that you heed the phrase &amp;quot;ID-type attribute&amp;quot; here. The &amp;lt;tt&amp;gt;id( )&amp;lt;/tt&amp;gt; function ignores any attributes whose ''names'' are &amp;quot;id,&amp;quot; unless they are declared in the document's DTD as being of the ID type. Thus:&lt;br /&gt;
&lt;br /&gt;
 id(&amp;quot;sect_01&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
successfully returns the &amp;lt;tt&amp;gt;book:section&amp;lt;/tt&amp;gt; element with that &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; attribute value, while:&lt;br /&gt;
&lt;br /&gt;
 id(&amp;quot;para_01&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
returns an empty node-set: the former &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; attribute is expressly declared to be an ID-type attribute in the document's DTD, while the latter is not. Perhaps more importantly, if there is no DTD at all — if the document is simply well formed — it doesn't make any difference what value you pass to the &amp;lt;tt&amp;gt;id( )&amp;lt;/tt&amp;gt; function; it will always in this case return an empty node-set. If you're uncertain whether an attribute named &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; is of the ID type — or know for sure that it isn't — test the attribute value in a location step's predicate, as in:&lt;br /&gt;
&lt;br /&gt;
 [@id=&amp;quot;para_01&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
or, if the context node is already the &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; attribute:&lt;br /&gt;
&lt;br /&gt;
 [.=&amp;quot;para_01&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
Such an approach, while perhaps more prosaic, is also closer to failure-proof. (XSLT users can also take advantage of &amp;lt;tt&amp;gt;keys&amp;lt;/tt&amp;gt; to ensure unique identifiers.)&lt;br /&gt;
&lt;br /&gt;
==== id( ) and node-set arguments ====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;id( )&amp;lt;/tt&amp;gt; function is unique among functions in the XPath spec in one regard. As with the other functions, if you pass it a value that is ''not'' a string, the value is treated as if it had been converted to a string by the &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; function (covered later in this chapter). Typically, when you pass &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; a node-set, it returns the string-value of only the ''first'' node in the node-set. However, when you pass &amp;lt;tt&amp;gt;id( )&amp;lt;/tt&amp;gt; a node-set, the function returns not only a single node (whose ID-type attribute's value would presumably match the string-value of the first node), but rather a node-set containing all element nodes whose ID-type attributes match any of the string-values of nodes in the passed node-set.&lt;br /&gt;
&lt;br /&gt;
==== local-name(nodeset?) ====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;local-name( )&amp;lt;/tt&amp;gt; function returns the name of a node, shorn of any namespace prefix. (You might call this the un-QName.) If the optional argument is not supplied, the function operates as if you had passed it a node-set consisting only of the context node. If the node-set contains more than one node, the function returns the local-name of only the first node (in document order) in the node-set:&lt;br /&gt;
&lt;br /&gt;
 local-name(//book:chapter)&lt;br /&gt;
&lt;br /&gt;
returns the string &amp;lt;tt&amp;gt;chapter&amp;lt;/tt&amp;gt; and:&lt;br /&gt;
&lt;br /&gt;
 local-name(//svg)&lt;br /&gt;
&lt;br /&gt;
returns the string &amp;lt;tt&amp;gt;svg&amp;lt;/tt&amp;gt;. On the other hand:&lt;br /&gt;
&lt;br /&gt;
 local-name(//book:section | //svg)&lt;br /&gt;
&lt;br /&gt;
(note the compound location path) returns the string &amp;lt;tt&amp;gt;section&amp;lt;/tt&amp;gt; — that is, the local-name of only the first node in the node-set.&lt;br /&gt;
&lt;br /&gt;
==== namespace-uri(nodeset?) ====&lt;br /&gt;
&lt;br /&gt;
When you need to know the URI associated with a given element or attribute's namespace in an instance document, call the &amp;lt;tt&amp;gt;namespace-uri( )&amp;lt;/tt&amp;gt; function. If you omit the optional argument, its default value is a node-set consisting of just the context node. If the node-set passed as the argument consists of more than one node, the function returns the URI associated with only the first node in the node-set. If the specified element or attribute has no associated URI, the function returns an empty string.&lt;br /&gt;
&lt;br /&gt;
In the sample XML document, each element node is associated with a namespace URI. The elements with explicit &amp;lt;tt&amp;gt;book&amp;lt;/tt&amp;gt;: prefixes are associated with the URIs tied to those prefixes via the namespace declarations for that prefix. For instance:&lt;br /&gt;
&lt;br /&gt;
 namespace-uri(/book:book)&lt;br /&gt;
&lt;br /&gt;
returns the string &amp;quot;http://mynamespace/uri.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Note that when an attribute node's name is unprefixed — even when there's an explicit ''default'' namespace declaration (&amp;lt;tt&amp;gt;xmlns&amp;lt;/tt&amp;gt; attribute) in effect for the node — the &amp;lt;tt&amp;gt;namespace-uri( )&amp;lt;/tt&amp;gt; function returns a null value. This expression:&lt;br /&gt;
&lt;br /&gt;
 namespace-uri(//circle@style)&lt;br /&gt;
&lt;br /&gt;
returns a null string.&lt;br /&gt;
&lt;br /&gt;
An attribute also does not acquire the namespace URI associated with the corresponding element automatically. For attributes in the sample document such as &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;style&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;cx&amp;lt;/tt&amp;gt;, an empty string is returned as the namespace URI. However, this expression:&lt;br /&gt;
&lt;br /&gt;
 namespace-uri(//book:ref/@xlink:href)&lt;br /&gt;
&lt;br /&gt;
returns the string &amp;quot;http://www.w3.org/1999/xlink/&amp;quot; — the URI associated (via the &amp;lt;tt&amp;gt;xmlns:xlink&amp;lt;/tt&amp;gt; declaration) with the attribute's &amp;lt;tt&amp;gt;xlink&amp;lt;/tt&amp;gt;: namespace prefix.&lt;br /&gt;
&lt;br /&gt;
By the way, as always when dealing with namespaces, remember that the exact namespace prefix is seldom relevant: what counts is the URI to which the namespace prefix is bound. For instance, at the time the XPath expression is evaluated — say, in an XSLT stylesheet or an XPointer — the namespace URI &amp;quot;http://mynamespace/uri&amp;quot; might be associated with the prefix &amp;lt;tt&amp;gt;mybook&amp;lt;/tt&amp;gt;:. In such a context, the following two function calls return exactly the same results as long as the document containing the XPath expression binds both prefixes to the same URI:&lt;br /&gt;
&lt;br /&gt;
 namespace-uri('''/book:'''book)&lt;br /&gt;
 namespace-uri('''/mybook:'''book)&lt;br /&gt;
&lt;br /&gt;
The document being evaluated by the expression needn't use either of those two prefixes in the element name, as long as whatever prefix it ''does'' use is bound to the &amp;quot;http://mynamespace/uri&amp;quot; URI.&lt;br /&gt;
&lt;br /&gt;
==== name(nodeset?) ====&lt;br /&gt;
&lt;br /&gt;
If your applications must refer to nodes in a namespace-aware fashion (as most applications do), the &amp;lt;tt&amp;gt;name( )&amp;lt;/tt&amp;gt; function will probably be the node-name function you'll use least often. That's because it returns the QName of the node-set passed (or defaulted) as its sole argument — the &amp;quot;intuitive&amp;quot; name, including both the namespace prefix and the local-name portion. Therefore, &amp;lt;tt&amp;gt;name( )&amp;lt;/tt&amp;gt; is truly reliable only when processing elements and attributes in no namespace at all. As in the other name-related functions, passing no argument at all causes &amp;lt;tt&amp;gt;name( )&amp;lt;/tt&amp;gt; to operate on a node-set consisting of just the context node; if the node-set argument includes more than one node, the function operates on only the first.&lt;br /&gt;
&lt;br /&gt;
On the face of it, using a function such as &amp;lt;tt&amp;gt;name( )&amp;lt;/tt&amp;gt; might seem superfluous. After all, the most common form of a location step includes an explicit node name, and if you already know the node's name, there's no need for a function to return it.&lt;br /&gt;
&lt;br /&gt;
Where it comes in handy is when you ''don't'' (for one reason or another) know the name of the node in question or simply need to test the name (particularly of an attribute) against a string. For instance, you might need to isolate the ''n''th child of a particular element, displaying its name and the names and values of all its attributes. Here's another example from XSLT using nested &amp;lt;tt&amp;gt;xsl:for-each&amp;lt;/tt&amp;gt; elements:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;lt;!-- Process the first child of each book:section element --&amp;gt;&lt;br /&gt;
 &amp;lt;xsl:template match=&amp;quot;/&lt;br /&gt;
    &amp;lt;xsl:for-each select=&amp;quot;book:section/*[1]&amp;quot;&amp;gt;&lt;br /&gt;
       &amp;amp;lt;!-- Display this child's name... --&amp;gt;&lt;br /&gt;
       The first child's name is &amp;lt;xsl:value-of select=&amp;quot;'''name(  )'''&amp;quot;/&amp;gt;,&lt;br /&gt;
       and it has the following attributes:&amp;amp;lt;br/&amp;gt;&lt;br /&gt;
       &amp;lt;xsl:for-each select=&amp;quot;@*&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;amp;lt;!-- ...and the name and value of each attribute --&amp;gt;&lt;br /&gt;
          &amp;lt;xsl:value-of select=&amp;quot;'''name(  )'''&amp;quot;/&amp;gt; = &amp;lt;xsl:value-of select=&amp;quot;.&amp;quot;/&amp;gt;&amp;amp;lt;br/&amp;gt;&lt;br /&gt;
       &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;
 &amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Applied to the sample XML document for this section, this template rule generates the text:&lt;br /&gt;
&lt;br /&gt;
 The first child's name is book:para, and it has the following attributes: &lt;br /&gt;
 id = para_01&lt;br /&gt;
&lt;br /&gt;
A special case of &amp;quot;not knowing the name of the node in question&amp;quot; occurs in generic XSLT stylesheets whose purpose is to ''describe'' the documents they process, displaying the names of the various nodes and their values. A portion of such a stylesheet might look something like the following:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;lt;!-- Process all element children of the context node --&amp;gt;&lt;br /&gt;
 &amp;lt;xsl:template match=&amp;quot;*&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;!-- Display the child element's name --&amp;gt;&lt;br /&gt;
    Child's name: &amp;lt;xsl:value-of select=&amp;quot;'''name(  )'''&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;amp;lt;!-- Display the child element's (string) value  --&amp;gt;&lt;br /&gt;
    Child's value: &amp;lt;xsl:value-of select=&amp;quot;.&amp;quot;/&amp;gt;&lt;br /&gt;
 &amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What makes this a special case is not necessarily that you really don't know the node's name — you may know very well what element names occur in your source document — rather, the general-purpose code doesn't ''care'' what the element's name is at this point; it treats all (child) elements the same way.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
In [[XPath and XPointer/XPath Basics|Chapter 2]], you saw something called an &amp;quot;expanded-name&amp;quot; for the various node types. I described an algorithm there for computing an expanded-name, consisting of the namespace URI, a plus sign, and the local-name of the node. You can use the same algorithm for computing the expanded-name with an XPath expression, by concatenating for a given name the value returned by the &amp;lt;tt&amp;gt;namespace-uri( )&amp;lt;/tt&amp;gt; function, the &amp;lt;tt&amp;gt;+&amp;lt;/tt&amp;gt;, and the value returned by the &amp;lt;tt&amp;gt;local-name( )&amp;lt;/tt&amp;gt; function. I'll show you how to do this concatenation in the next section, in the discussion of the &amp;lt;tt&amp;gt;concat( )&amp;lt;/tt&amp;gt; string function.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;sidebar&amp;quot;&amp;gt;&lt;br /&gt;
'''Names and Nodes'''&lt;br /&gt;
&lt;br /&gt;
Although the node-set functions — such as &amp;lt;tt&amp;gt;count( )&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;position( )&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;name( )&amp;lt;/tt&amp;gt; — are most often (and most &amp;quot;naturally&amp;quot;) employed in locating and otherwise processing element and attribute nodes, nothing inherently constrains these functions to operating on only those node types. (The exception is &amp;lt;tt&amp;gt;id( )&amp;lt;/tt&amp;gt;. Its focus is strictly on dealing with element nodes, because they're the only node type that can be accessed by way of ID-type attributes.)&lt;br /&gt;
&lt;br /&gt;
For example, you can count the number of text nodes in a document with an expression such as:&lt;br /&gt;
&lt;br /&gt;
 count(//text(  ))&lt;br /&gt;
&lt;br /&gt;
which uses the &amp;lt;tt&amp;gt;text( )&amp;lt;/tt&amp;gt; node-type test to restrict the resulting node-set only to text nodes.&lt;br /&gt;
&lt;br /&gt;
Remember too that not only elements and attributes but also PIs have names. A PI's name isn't associated with any particular namespace so the &amp;lt;tt&amp;gt;name( )&amp;lt;/tt&amp;gt; function always returns just the PI's target. In this case, the value returned by the &amp;lt;tt&amp;gt;local-name( )&amp;lt;/tt&amp;gt; function is identical to the value returned by the &amp;lt;tt&amp;gt;name( )&amp;lt;/tt&amp;gt; function. (Indeed, that is true for ''all'' node types except elements and attributes.) The value returned by the &amp;lt;tt&amp;gt;namespace-uri( )&amp;lt;/tt&amp;gt; function when applied to a PI is an empty string.&lt;br /&gt;
&lt;br /&gt;
If the first node in the node-set handled by &amp;lt;tt&amp;gt;local-name( )&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;namespace-uri( )&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;name( )&amp;lt;/tt&amp;gt; is the root node, a comment, or a text node, the returned value is likewise an empty string. These node types do not have anything remotely like a &amp;quot;name.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Rather bizarrely, in my opinion, namespace nodes have expanded names. The local part of a namespace node's expanded-name is the prefix associated with that namespace; if there is no prefix (in the case of elements and attributes in the default namespace), this local-name is an empty string. The namespace URI for a namespace node is always null. In the sample document, which declares three namespaces in the root element, all elements thus have three namespace nodes associated with them (counting the namespace implicitly associated with the built-in &amp;lt;tt&amp;gt;xml&amp;lt;/tt&amp;gt;: prefix); their expanded names are, respectively, &amp;lt;tt&amp;gt;book&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;xlink&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;xml&amp;lt;/tt&amp;gt;, and an empty string.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== String Functions ===&lt;br /&gt;
&lt;br /&gt;
The set of XPath functions that operate on string arguments and/or return strings is extensive. Used in XSLT stylesheets, these functions give you enormous flexibility in terms of generating new content based on content in the source tree. In XPointers, you'll find yourself using them most often in the predicate of XPath location steps.&lt;br /&gt;
&lt;br /&gt;
Examples in this section all assume that the following XML document is being navigated via XPath:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;dated_relics xmlns=&amp;quot;http://mynamespace&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;relic&amp;gt;&lt;br /&gt;
      &amp;lt;name&amp;gt;Smurf&amp;lt;/name&amp;gt;&lt;br /&gt;
      &amp;lt;price currency=&amp;quot;USD&amp;quot;&amp;gt;9.00&amp;lt;/price&amp;gt;&lt;br /&gt;
   &amp;lt;/relic&amp;gt;&lt;br /&gt;
   &amp;lt;relic&amp;gt;&lt;br /&gt;
      &amp;lt;name&amp;gt;lava lamp&amp;lt;/name&amp;gt;&lt;br /&gt;
      &amp;lt;price currency=&amp;quot;GBP&amp;quot;&amp;gt;39.95&amp;lt;/price&amp;gt;&lt;br /&gt;
   &amp;lt;/relic&amp;gt;&lt;br /&gt;
   &amp;lt;relic&amp;gt;&lt;br /&gt;
      &amp;lt;name&amp;gt;beanbag chair&amp;lt;/name&amp;gt;&lt;br /&gt;
      &amp;lt;price currency=&amp;quot;EU&amp;quot;&amp;gt;70.75&amp;lt;/price&amp;gt;&lt;br /&gt;
   &amp;lt;/relic&amp;gt;&lt;br /&gt;
   &amp;lt;relic&amp;gt;&lt;br /&gt;
      &amp;lt;name&amp;gt;love bead bracelet&amp;lt;/name&amp;gt;&lt;br /&gt;
      &amp;lt;price currency=&amp;quot;GBP&amp;quot;&amp;gt;.37&amp;lt;/price&amp;gt;&lt;br /&gt;
   &amp;lt;/relic&amp;gt;&lt;br /&gt;
   &amp;lt;relic&amp;gt;&lt;br /&gt;
      &amp;lt;name&amp;gt;blacklight&amp;lt;/name&amp;gt;&lt;br /&gt;
      &amp;lt;price currency=&amp;quot;USD&amp;quot;&amp;gt;323.65&amp;lt;/price&amp;gt;&lt;br /&gt;
   &amp;lt;/relic&amp;gt;&lt;br /&gt;
   &amp;lt;relic&amp;gt;&lt;br /&gt;
      &amp;lt;name&amp;gt;VW mini-bus&amp;lt;/name&amp;gt;&lt;br /&gt;
      &amp;lt;price currency=&amp;quot;USD&amp;quot;&amp;gt;8500.00&amp;lt;/price&amp;gt;&lt;br /&gt;
   &amp;lt;/relic&amp;gt;&lt;br /&gt;
   &amp;lt;relic&amp;gt;&lt;br /&gt;
      &amp;lt;name&amp;gt;open-hand chair&amp;lt;/name&amp;gt;&lt;br /&gt;
      &amp;lt;price currency=&amp;quot;JPY&amp;quot;&amp;gt;16865.78&amp;lt;/price&amp;gt;&lt;br /&gt;
   &amp;lt;/relic&amp;gt;&lt;br /&gt;
&amp;lt;/dated_relics&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[XPath and XPointer/XPath Functions and Numeric Operators#xpathpointer-CHP-4-TABLE-2|Table 4-2]] summarizes the XPath string functions. A detailed discussion of each follows the table.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;xpathpointer-CHP-4-TABLE-2&amp;quot;&amp;gt;&lt;br /&gt;
'''Table 4-2. String functions'''&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Function prototype !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 string(anytype?)&lt;br /&gt;
| String || Returns the value of the &amp;lt;tt&amp;gt;anytype&amp;lt;/tt&amp;gt; argument converted to a string&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 concat(string1, string2, ...)&lt;br /&gt;
| String || Concatenates the values of the passed arguments into a single string and returns that string's value&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 starts-with(string1, string2)&lt;br /&gt;
| boolean || Returns true if &amp;lt;tt&amp;gt;string1&amp;lt;/tt&amp;gt; begins with &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt;, false otherwise&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 contains(string1, string2)&lt;br /&gt;
| boolean || Returns true if &amp;lt;tt&amp;gt;string1&amp;lt;/tt&amp;gt; contains &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt;, false otherwise&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 substring(string, number1, number2?)&lt;br /&gt;
| String || Returns the portion of &amp;lt;tt&amp;gt;string&amp;lt;/tt&amp;gt; starting at character &amp;lt;tt&amp;gt;number1&amp;lt;/tt&amp;gt;, for a length of &amp;lt;tt&amp;gt;number2&amp;lt;/tt&amp;gt; characters&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 substring-before(string1, string2)&lt;br /&gt;
| String || Returns the portion of &amp;lt;tt&amp;gt;string1&amp;lt;/tt&amp;gt; occurring before &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 substring-after(string1, string2)&lt;br /&gt;
| String || Returns the portion of &amp;lt;tt&amp;gt;string1&amp;lt;/tt&amp;gt; following &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 string-length(string?)&lt;br /&gt;
| Number || Returns the number of characters in &amp;lt;tt&amp;gt;string&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 normalize-space(string?)&lt;br /&gt;
| String || Returns the whitespace-normalized value of &amp;lt;tt&amp;gt;string&amp;lt;/tt&amp;gt; (that is, stripped of leading and trailing spaces, with multiple consecutive occurrences of whitespace replaced by a single space)&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 translate(string1, string2, string3)&lt;br /&gt;
| String || Replaces individual characters appearing in both &amp;lt;tt&amp;gt;string1&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt; with corresponding characters in &amp;lt;tt&amp;gt;string3&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== string(anytype?) ====&lt;br /&gt;
&lt;br /&gt;
As you might guess from its name, the &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; function converts the optional argument to a string of characters. There's a set of rules for the way in which this conversion takes place, dependent on the data type of the argument:&lt;br /&gt;
&lt;br /&gt;
'''''When anytype is a node-set.''''' When the argument is a node-set (for example, one returned by a location path), &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; returns the string-value of the first node in the node-set. If the indicated node-set is empty, the returned value is an empty string. If the argument is missing, it defaults to a node-set whose only member is the context node at the point of the call to &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''''When anytype is a number.''''' If you pass &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; an integer numeric argument, results are pretty much what you'd expect: you get back the number in the form of a string (e.g., &amp;quot;365&amp;quot; instead of 365). A fixed- or floating-point number is converted to a string including a decimal point, at least one number to the left and one to the right of the decimal point, and an optional minus sign (for negative numbers only, obviously). The spec says that the number of trailing zeros in the latter case will always be sufficient only to distinguish the number from all other legal (IEEE 754) numeric values.&lt;br /&gt;
&lt;br /&gt;
Refer back to the sample XML document. Passing &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; the value of a &amp;lt;tt&amp;gt;price&amp;lt;/tt&amp;gt; element should produce different results, depending on the &amp;lt;tt&amp;gt;price&amp;lt;/tt&amp;gt; element. Consider:&lt;br /&gt;
&lt;br /&gt;
 string(number(price))&lt;br /&gt;
&lt;br /&gt;
Here, the price of a Smurf should be returned as the string &amp;quot;9&amp;quot; (no leading or trailing zeros, because none are needed to distinguish this or any other integer from all other legal numeric values), the price of a love bead bracelet as the string &amp;quot;0.37&amp;quot; (including a leading zero), and the price of any of the other relics in the document as simply the string-value of the element's text node (e.g., the string &amp;quot;39.95&amp;quot; for the lava lamp).&lt;br /&gt;
&lt;br /&gt;
Any form of the number 0, including positive and negative 0, is converted to the string &amp;quot;0.&amp;quot; Positive infinity&amp;lt;ref&amp;gt;Which I think of as one more than a gazillion.&amp;lt;/ref&amp;gt; is represented as the string &amp;quot;Infinity&amp;quot;; negative infinity is represented the same way, prepended with a minus sign: &amp;quot;-Infinity.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You may encounter one other oddball condition when passing &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; a numeric argument, which arises when the argument is only ''supposedly'' a number, but for one reason or another is not. As mentioned in [[XPath and XPointer/XPath Basics|Chapter 2]] in the discussion of data types, XPath represents a number-that-isn't-a-number with the special value, &amp;lt;tt&amp;gt;NaN&amp;lt;/tt&amp;gt;; if &amp;lt;tt&amp;gt;NaN&amp;lt;/tt&amp;gt; (either literally or as the result of some calculation or function call) is passed to &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt;, the returned value is the ''string'' &amp;quot;NaN.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
The XPath Recommendation points out that passing numeric values to the &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; function is not intended to solve the general problem of formatting numbers as strings — for example, grouping every three positions with commas, forcing specific numbers of leading zeros, and so on. If you're using XSLT, you can do all this with the &amp;lt;tt&amp;gt;format-number( )&amp;lt;/tt&amp;gt; function and the &amp;lt;tt&amp;gt;xsl:number&amp;lt;/tt&amp;gt; element.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''When anytype is a Boolean.''''' A Boolean argument to &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; returns either the value &amp;quot;true&amp;quot; or &amp;quot;false,&amp;quot; depending on the value of the argument.&lt;br /&gt;
&lt;br /&gt;
'''''When anytype is a string.''''' A string argument passed to &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; returns the same string.&lt;br /&gt;
&lt;br /&gt;
'''''When anytype is any other data type.''''' In a burst of involuted prose, the XPath spec says, &amp;quot;An object of a type other than the four basic types is converted to a string in a way that is dependent on that type.&amp;quot; Let's see, the data types allowed under XPath are string, numeric, node-set, Boolean, and, uh....&lt;br /&gt;
&lt;br /&gt;
This clause has been added to future-proof XPath against the introduction of new data types. In theory, the specifier (W3C or otherwise) of such a new data type would be obliged to provide some statement of how its values are to be represented as strings: how to derive their string-values, in short.&lt;br /&gt;
&lt;br /&gt;
For instance, some future version of XPath (or an XPath-aware spec) might include a currency data type. This hypothetical spec might then say something like, &amp;quot;When represented as a string, values of the currency data type will include at least one integer (possibly 0) to the left of the decimal point, the decimal point itself, and at least a two-digit integer to the right of the decimal point, preceded by an optional minus sign and preceded or followed by an optional currency symbol.&amp;quot; And there would be your definition of how to expect &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; to behave when passed a currency value.&lt;br /&gt;
&lt;br /&gt;
(How, exactly, an XPath function such as &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; is to know all these outside-of-XPath data conversion rules is a tricky question wisely sidestepped by the XPath spec.)&lt;br /&gt;
&lt;br /&gt;
==== concat(string1, string2, ...) ====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;concat( )&amp;lt;/tt&amp;gt; function takes at least two arguments and forges them into a single string. The function provides no padding with whitespace, so if you're constructing (say) a list of tokens, or a set of words into a phrase or sentence, you've got to include the &amp;quot; &amp;quot; characters and perhaps punctuation separating one from the other. For instance, assume that the context node at a given point is any of the &amp;lt;tt&amp;gt;relic&amp;lt;/tt&amp;gt; elements in the sample XML document. Then:&lt;br /&gt;
&lt;br /&gt;
 concat(price, &amp;quot; (&amp;quot;, price/@currency, &amp;quot;)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
builds a string consisting of that relic's price, a space an opening parenthesis, the currency in which the price is represented, and a closing parenthesis. Given our sample document, for the seven relics in question, this would yield the strings (respectively):&lt;br /&gt;
&lt;br /&gt;
9.00 (USD)&amp;lt;br/&amp;gt;39.95 (GBP)&amp;lt;br/&amp;gt;70.75 (EU)&amp;lt;br/&amp;gt;.37 (GBP)&amp;lt;br/&amp;gt;323.65 (USD)&amp;lt;br/&amp;gt;8500.00 (USD)&lt;br /&gt;
&lt;br /&gt;
Note that the figures 9.00, .37, and 8500.00 do not follow the rules outlined above for representing numeric values as strings. If for some reason you want to force this representation, you need to explicitly convert the &amp;lt;tt&amp;gt;price&amp;lt;/tt&amp;gt; element nodes' string-values to numbers (using the &amp;lt;tt&amp;gt;number( )&amp;lt;/tt&amp;gt; function discussed later), pass this result to &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt;, and finally, pass that function's result to &amp;lt;tt&amp;gt;concat( )&amp;lt;/tt&amp;gt; as its first argument. Like this:&lt;br /&gt;
&lt;br /&gt;
 concat('''string(number(price))''', &amp;quot; (&amp;quot;, &lt;br /&gt;
    price/@currency, &amp;quot;)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Also note in this case that the call to &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; is optional. Because &amp;lt;tt&amp;gt;concat( )&amp;lt;/tt&amp;gt; expects a string-type argument, it does any necessary conversion automatically.&lt;br /&gt;
&lt;br /&gt;
Earlier in this chapter, in the discussion of name-related node-set functions, I mentioned that the &amp;lt;tt&amp;gt;concat( )&amp;lt;/tt&amp;gt; function could be used to build an expanded-name for a given element. Following the logic of James Clark's algorithm for this process, you can build an expanded-name for a given name using:&lt;br /&gt;
&lt;br /&gt;
 concat(namespace-uri(''node''), &amp;quot;+&amp;quot;, local-name(''node''))&lt;br /&gt;
&lt;br /&gt;
Thus, if &amp;lt;tt&amp;gt;node&amp;lt;/tt&amp;gt; is a &amp;lt;tt&amp;gt;relic&amp;lt;/tt&amp;gt; element from our sample XML document, the function call returns the string &amp;quot;http://mynamespace+relic.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== starts-with(string1, string2) ====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;starts-with( )&amp;lt;/tt&amp;gt; function takes two arguments, returning either the Boolean value true if the first argument starts with the value of the second, or false otherwise.&lt;br /&gt;
&lt;br /&gt;
Returning Boolean values makes &amp;lt;tt&amp;gt;starts-with()&amp;lt;/tt&amp;gt; useful primarily in a location step's predicate. Thus:&lt;br /&gt;
&lt;br /&gt;
 //price[starts-with(., &amp;quot;.&amp;quot;)]&lt;br /&gt;
&lt;br /&gt;
selects all the &amp;lt;tt&amp;gt;price&amp;lt;/tt&amp;gt; elements whose string-values start with decimal points (i.e., no leading zeros or other digits). For our sample document, the resulting node-set consists of a single &amp;lt;tt&amp;gt;price&amp;lt;/tt&amp;gt; element: the one for the love bead bracelet, with a string-value of &amp;quot;.37.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== contains(string1, string2) ====&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;tt&amp;gt;starts-with( )&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;contains( )&amp;lt;/tt&amp;gt; function returns a Boolean true or false and, hence, is most commonly used in a predicate. And it too takes two arguments. The value returned by the function is true if the first argument contains the second, or false otherwise.&lt;br /&gt;
&lt;br /&gt;
In our sample document, we could extract a node-set consisting of all relics that are chairs using a location path such as:&lt;br /&gt;
&lt;br /&gt;
 //relic[contains(name, &amp;quot;chair&amp;quot;)]&lt;br /&gt;
&lt;br /&gt;
This would locate a two-node node-set: the &amp;lt;tt&amp;gt;relic&amp;lt;/tt&amp;gt; node representing a beanbag chair and the &amp;lt;tt&amp;gt;relic&amp;lt;/tt&amp;gt; node representing an open-hand chair.&lt;br /&gt;
&lt;br /&gt;
==== substring(string, number1, number2?) ====&lt;br /&gt;
&lt;br /&gt;
Like most programming languages, XPath provides a &amp;lt;tt&amp;gt;substring( )&amp;lt;/tt&amp;gt; function for extracting a portion of a larger string. (Some languages, notably those derived from BASIC, call this the &amp;lt;tt&amp;gt;mid( )&amp;lt;/tt&amp;gt; function instead.) It takes at least two arguments: the larger string from which you want to select a portion and the starting point for the selection. A third optional argument can specify the number of characters to be extracted; if this argument isn't supplied, the extraction starts at character &amp;lt;tt&amp;gt;number1&amp;lt;/tt&amp;gt; and goes to the end of first string.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;note&amp;quot;&amp;gt;&lt;br /&gt;
'''Note'''&lt;br /&gt;
&lt;br /&gt;
If you're coming to XPath from a programming language that uses 0-based indexing (such as Java), in which the first item is #0, the second #1, and so on, be aware that XPath is 1-based: the first item is #1, and so on. That is, to select the first character of a string, use:&lt;br /&gt;
&lt;br /&gt;
 substring(''string'', '''1''', 1)&lt;br /&gt;
&lt;br /&gt;
not:&lt;br /&gt;
&lt;br /&gt;
 substring(''string'', '''0''', 1)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What happens when the number passed as the third argument exceeds the length of the string in question? This is not an error; the function behaves as though you hadn't passed a third argument at all. If the value of the ''second'' argument is greater than the length of the string, you'll get back an empty string as a result.&lt;br /&gt;
&lt;br /&gt;
One way in which I occasionally use the &amp;lt;tt&amp;gt;substring( )&amp;lt;/tt&amp;gt; function is during testing of an XSLT stylesheet. At this point, I really don't care to see the complete contents of text nodes, particularly lengthy ones. All I care to see is that the correct text nodes are showing up in the right places. So I use &amp;lt;tt&amp;gt;substring( )&amp;lt;/tt&amp;gt; to return, say, just the first five characters of a text node, with an ellipsis ( &amp;lt;tt&amp;gt;. . .&amp;lt;/tt&amp;gt; ) appended. Something like this:&lt;br /&gt;
&lt;br /&gt;
 concat(substring(node, 1, 5), &amp;quot;...&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Given the sample XML document used in this section, when iterating through a node-set consisting of all the &amp;lt;tt&amp;gt;name&amp;lt;/tt&amp;gt; elements, this returns a series of substrings such as the following:&lt;br /&gt;
&lt;br /&gt;
Smurf...&amp;lt;br/&amp;gt;lava ...&amp;lt;br/&amp;gt;beanb...&amp;lt;br/&amp;gt;love ...&amp;lt;br/&amp;gt;black...&amp;lt;br/&amp;gt;VW mi...&amp;lt;br/&amp;gt;open-...&lt;br /&gt;
&lt;br /&gt;
==== substring-before(string1, string2) and substring-after(string1, string2) ====&lt;br /&gt;
&lt;br /&gt;
These two functions work very similarly. They each take two arguments: a string from which you want a portion of text extracted and a string where you want the extraction terminated or begun, respectively. In either case, the &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt; argument doesn't appear in the result returned by the function; it's simply used as a breakpoint. If &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt; doesn't appear in &amp;lt;tt&amp;gt;string1&amp;lt;/tt&amp;gt; at all, the function returns an empty string.&lt;br /&gt;
&lt;br /&gt;
Consider a check-writing application using the values of the &amp;lt;tt&amp;gt;price&amp;lt;/tt&amp;gt; elements from this section's sample XML document. Such an application takes a number such as &amp;quot;12.34&amp;quot; (assuming that what is represented is in U.S. dollars) and converts it to a phrase like &amp;quot;12 dollars and 34 cents.&amp;quot; You could use the decimal point in the &amp;lt;tt&amp;gt;price&amp;lt;/tt&amp;gt; element as the &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt; breakpoint for calling both &amp;lt;tt&amp;gt;substring-before( )&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;substring-after( )&amp;lt;/tt&amp;gt;, like this:&lt;br /&gt;
&lt;br /&gt;
 concat(substring-before(price, &amp;quot;.&amp;quot;), &amp;quot; dollars and &amp;quot;, &lt;br /&gt;
    substring-after(price, &amp;quot;.&amp;quot;), &amp;quot; cents&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
This would naturally have to be tweaked in various ways to be perfectly workable. You'd have to come up with alternative phrasing for non-U.S. currency and also provide for the likelihood that a given price (such as that of the love beads) lacks anything at all to the left of its decimal point. But as a demonstration of the two functions in action, it works just fine.&lt;br /&gt;
&lt;br /&gt;
==== string-length(string?) ====&lt;br /&gt;
&lt;br /&gt;
Given a passed string argument, the &amp;lt;tt&amp;gt;string-length( )&amp;lt;/tt&amp;gt; function returns the number of characters it contains. If no argument is passed, the function operates on the context node's string-value.&lt;br /&gt;
&lt;br /&gt;
This function is sometimes directly useful in its own right. For example, you can use it to tell you whether one string is longer than another (apply it to the two strings and compare the two values returned). More often, though, you'll see &amp;lt;tt&amp;gt;string-length( )&amp;lt;/tt&amp;gt; used as an argument passed to another function — or the values returned by other functions as arguments passed to ''it''. For instance:&lt;br /&gt;
&lt;br /&gt;
 string-length(substring-before(price, &amp;quot;.&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
This returns the number of digits to the left of the decimal point in a &amp;lt;tt&amp;gt;price&amp;lt;/tt&amp;gt; element's string-value, which might be useful information in formatting the number a certain way.&lt;br /&gt;
&lt;br /&gt;
==== normalize-space(string?) ====&lt;br /&gt;
&lt;br /&gt;
If you've spent any time at all poking around XML-related specifications, you've probably come across the verb &amp;quot;normalize&amp;quot; and its variants. The issue here is that an XML parser is required to preserve whitespace found in a source document — to pass it unchanged to a downstream application. To normalize content is to remove extraneous whitespace — to trim leading and trailing whitespace from strings (such as text nodes) and replace multiple successive occurrences of whitespace ''within'' a string with a single blank space.&lt;br /&gt;
&lt;br /&gt;
That's what the &amp;lt;tt&amp;gt;normalize-space( )&amp;lt;/tt&amp;gt; function does, cleaning up the extraneous whitespace in a string so that what's left is &amp;quot;pure content.&amp;quot; Why would you want to do this? Because if the text content of a document has been hand-entered, you want to be sure that no extra space has crept in as a result of keyboard errors. This extra space can make comparing one string-value to another fail, even when the two nodes are apparently identical. For instance:&lt;br /&gt;
&lt;br /&gt;
 item1&lt;br /&gt;
&lt;br /&gt;
and:&lt;br /&gt;
&lt;br /&gt;
 item1&lt;br /&gt;
&lt;br /&gt;
are not &amp;quot;equal,&amp;quot; although they may appear so to a casual human observer; the second &amp;lt;tt&amp;gt;item1&amp;lt;/tt&amp;gt; is preceded and followed by newlines. That is, their ''normalized'' values — as returned by &amp;lt;tt&amp;gt;normalize-space( )&amp;lt;/tt&amp;gt;, say — are equal, but their &amp;quot;raw&amp;quot; values are not.&lt;br /&gt;
&lt;br /&gt;
Note that fixing up extraneous whitespace within a string isn't the same as removing whitespace-only text nodes. Needing to do ''that'' isn't necessarily a problem in its own right, but can be a very big problem in XSLT applications, where the extra text nodes can play havoc with operations, such as processing even-numbered nodes one way and odd-numbered nodes a different way. This is such a big issue in XSLT that the specification includes some of its own facilities for handling such text nodes. For example, there are both &amp;lt;tt&amp;gt;xsl:strip-space&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;xsl:preserve-space&amp;lt;/tt&amp;gt; elements for identifying the whitespace-only text nodes you want collapsed or preserved, respectively.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;normalize-space( )&amp;lt;/tt&amp;gt; function addresses this potential problem by ensuring that you're dealing only with the true &amp;lt;tt&amp;gt;#PCDATA&amp;lt;/tt&amp;gt; content in a complete document or any of its nodes: pass it a string, get back the normalized result; pass it any other data type, get back the normalized corresponding string-value; and pass it nothing at all to get back the normalized string-value of the context node.&lt;br /&gt;
&lt;br /&gt;
==== translate(string1, string2, string3) ====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;translate( )&amp;lt;/tt&amp;gt; function replaces individual characters in one string with ''different'' individual characters. The &amp;lt;tt&amp;gt;string1&amp;lt;/tt&amp;gt; argument is the string whose characters you want to replace; &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt; includes the specific characters in &amp;lt;tt&amp;gt;string1&amp;lt;/tt&amp;gt; that you want to replace; and &amp;lt;tt&amp;gt;string3&amp;lt;/tt&amp;gt; includes the characters with which you want to replace those &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt; characters. So:&lt;br /&gt;
&lt;br /&gt;
 translate(&amp;quot;1234567890&amp;quot;, &amp;quot;126&amp;quot;, &amp;quot;ABX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
replaces each occurrence of any of the single characters &amp;quot;1,&amp;quot; &amp;quot;2,&amp;quot; or &amp;quot;6,&amp;quot; with the single character &amp;quot;A,&amp;quot; &amp;quot;B,&amp;quot; or &amp;quot;X,&amp;quot; respectively. The value returned from this function call would thus be the string &amp;quot;AB2345X7890.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;tt&amp;gt;normalize-space( )&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;translate( )&amp;lt;/tt&amp;gt; function can be valuable in ensuring that two strings are equal, especially when their case — upper vs. lower — is possibly different, even though they're otherwise apparently identical. Instead of comparing the two strings directly, compare their case-folded values using &amp;lt;tt&amp;gt;translate( )&amp;lt;/tt&amp;gt;. Thus:&lt;br /&gt;
&lt;br /&gt;
 translate(somestring, &lt;br /&gt;
    &amp;quot;abcdefghijklmnopqrstuvwxyz&amp;quot;, &lt;br /&gt;
    &amp;quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Every lowercase &amp;quot;a&amp;quot; in &amp;lt;tt&amp;gt;somestring&amp;lt;/tt&amp;gt; is replaced with a capital &amp;quot;A,&amp;quot; every &amp;quot;b&amp;quot; with a &amp;quot;B,&amp;quot; and so on. Characters in &amp;lt;tt&amp;gt;somestring&amp;lt;/tt&amp;gt; that don't match any characters in &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt; appear unchanged in the result.&lt;br /&gt;
&lt;br /&gt;
Note that the lengths of &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;string3&amp;lt;/tt&amp;gt; are usually identical but don't need to be. If &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt; is longer than &amp;lt;tt&amp;gt;string3&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;translate( )&amp;lt;/tt&amp;gt; serves to ''remove'' characters from &amp;lt;tt&amp;gt;string1&amp;lt;/tt&amp;gt;. So:&lt;br /&gt;
&lt;br /&gt;
 translate(somestring, &lt;br /&gt;
    &amp;quot;abcdefghijklmnopqrstuvwxyz&amp;quot;, &lt;br /&gt;
    &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
removes from &amp;lt;tt&amp;gt;somestring&amp;lt;/tt&amp;gt; all lowercase letters, while:&lt;br /&gt;
&lt;br /&gt;
 translate(somestring, &lt;br /&gt;
    &amp;quot;abcdefghijklmnopqrstuvwxyz&amp;quot;, &lt;br /&gt;
    &amp;quot;ABCDEFGHIJKLM&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
uppercases all lowercase letters in &amp;lt;tt&amp;gt;somestring&amp;lt;/tt&amp;gt; in the first half of the alphabet and removes all those appearing in the second half. If &amp;lt;tt&amp;gt;somestring&amp;lt;/tt&amp;gt; is &amp;quot;VW mini-bus,&amp;quot; this returns the string &amp;quot;VW MII-B&amp;quot;: the uppercase letters &amp;quot;VW&amp;quot; (uppercase letters don't appear in &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt;, so they're passed unchanged), a space, the uppercased &amp;quot;mi&amp;quot; and &amp;quot;i&amp;quot; from &amp;quot;mini,&amp;quot; the hyphen, and the uppercased &amp;quot;b&amp;quot; from &amp;quot;bus.&amp;quot; The &amp;quot;n&amp;quot; in &amp;quot;mini&amp;quot; and the &amp;quot;us&amp;quot; in &amp;quot;bus&amp;quot; are suppressed.&lt;br /&gt;
&lt;br /&gt;
If for some reason it's desirable, &amp;lt;tt&amp;gt;string3&amp;lt;/tt&amp;gt; may be longer than &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt;. This is not necessary, because the function considers only those characters in &amp;lt;tt&amp;gt;string3&amp;lt;/tt&amp;gt; up to the length of &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt;; it's just like you omitted those characters from &amp;lt;tt&amp;gt;string3&amp;lt;/tt&amp;gt; in the first place.&lt;br /&gt;
&lt;br /&gt;
One interesting use of &amp;lt;tt&amp;gt;translate( )&amp;lt;/tt&amp;gt;, in conjunction with &amp;lt;tt&amp;gt;normalize-space( )&amp;lt;/tt&amp;gt;, is to &amp;quot;depunctuate&amp;quot; a string. Thus, you can turn the string &amp;quot;Eek!!! Is that a mouse, or what?&amp;quot; into &amp;quot;Eek Is that a mouse or what&amp;quot; using:&lt;br /&gt;
&lt;br /&gt;
 normalize-space(translate(&amp;quot;Eek!!! Is that a mouse, or what?&amp;quot;, &amp;quot;!,?&amp;quot;,&lt;br /&gt;
    &amp;quot;   &amp;quot;))&lt;br /&gt;
&lt;br /&gt;
Here, the &amp;lt;tt&amp;gt;translate( )&amp;lt;/tt&amp;gt; function itself replaces each occurrence of the exclamation mark, comma, and question mark characters with a blank space; the outer call to &amp;lt;tt&amp;gt;normalize-space( )&amp;lt;/tt&amp;gt; then squashes all the resulting multiple blank spaces between words into one. (If you need to do this, be sure that the length of &amp;lt;tt&amp;gt;string3&amp;lt;/tt&amp;gt; — the blank spaces — matches the number of characters in &amp;lt;tt&amp;gt;string2&amp;lt;/tt&amp;gt; exactly.)&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;tt&amp;gt;translate( )&amp;lt;/tt&amp;gt; can be useful for limited cases, it's not really a good general-purpose &amp;quot;search-and-replace&amp;quot; tool — particularly because you can use it only to do single-character matches and replacements. If you need to replace a single character with two or more characters, two or more characters with a single one, or two or more characters with a different set of characters — or a word or phrase with an entirely different one — &amp;lt;tt&amp;gt;translate( )&amp;lt;/tt&amp;gt; won't help much, if at all.&lt;br /&gt;
&lt;br /&gt;
In this case, you'll have to do more exotic string manipulation, perhaps with XSLT or a programming language.&lt;br /&gt;
&lt;br /&gt;
=== Boolean Functions ===&lt;br /&gt;
&lt;br /&gt;
As the term implies, the XPath Boolean functions all return Boolean true or false values. (And when you hear the word Boolean in an XPath context, a little flag should go up in your head as you think, &amp;quot;Predicate.&amp;quot; Hold that thought.)&lt;br /&gt;
&lt;br /&gt;
These functions are all quite simple, with few little gotchas or complications. Thus, I don't think it's necessary to provide a sample XML document for them. But following [[XPath and XPointer/XPath Functions and Numeric Operators#xpathpointer-CHP-4-TABLE-3|Table 4-3]], which summarizes the Boolean functions, I will provide discussion and examples of each.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;xpathpointer-CHP-4-TABLE-3&amp;quot;&amp;gt;&lt;br /&gt;
'''Table 4-3. Boolean functions'''&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Function prototype !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 boolean(anytype)&lt;br /&gt;
| boolean || Converts &amp;lt;tt&amp;gt;anytype&amp;lt;/tt&amp;gt; to a Boolean true or false value&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 not(boolean)&lt;br /&gt;
| boolean || Returns true if &amp;lt;tt&amp;gt;boolean&amp;lt;/tt&amp;gt; is false, and false if &amp;lt;tt&amp;gt;boolean&amp;lt;/tt&amp;gt; is true&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 true(  )&lt;br /&gt;
| boolean || Returns the value true&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 false(  )&lt;br /&gt;
| boolean || Returns the value false&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 lang(string)&lt;br /&gt;
| boolean || Returns true or false, depending on whether the language in which the context node is presented matches the value of the &amp;lt;tt&amp;gt;string&amp;lt;/tt&amp;gt; argument&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== boolean(anytype) ====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;boolean( )&amp;lt;/tt&amp;gt; function is similar to the &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; function introduced in the last section: it examines the argument passed to it and returns a value (true or false) depending on the argument's value and data type. Also like the &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; function, you will almost never need to use &amp;lt;tt&amp;gt;boolean( )&amp;lt;/tt&amp;gt; explicitly: in contexts (particularly predicates) where a logical true or false is expected, the &amp;lt;tt&amp;gt;anytype&amp;lt;/tt&amp;gt; argument will be converted implicitly, according to the type (string, numeric, node-set, or Boolean) of the argument. Thus, each of the following subsections describes these implicit conversions as well as the result of explicit calls to &amp;lt;tt&amp;gt;boolean( )&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''''When anytype is a string.''''' If &amp;lt;tt&amp;gt;anytype&amp;lt;/tt&amp;gt; is at least one character long, the call to &amp;lt;tt&amp;gt;boolean( )&amp;lt;/tt&amp;gt; returns true; otherwise, it returns false. Thus, the following two XPath expressions are functionally identical (the value true):&lt;br /&gt;
&lt;br /&gt;
 boolean(&amp;quot;some string&amp;quot;)&lt;br /&gt;
 string-length(&amp;quot;some-string&amp;quot;) &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
Remember that a text node may consist entirely of whitespace, as discussed earlier. This whitespace may fool the human eye but won't fool the &amp;lt;tt&amp;gt;boolean( )&amp;lt;/tt&amp;gt; function; newlines, spaces, tabs, and so on each count as a string with a length greater than 0.&lt;br /&gt;
&lt;br /&gt;
'''''When anytype is numeric.''''' A call to &amp;lt;tt&amp;gt;boolean( )&amp;lt;/tt&amp;gt; with a numeric argument returns true if the argument is a legitimate number (i.e., not the special &amp;lt;tt&amp;gt;NaN&amp;lt;/tt&amp;gt; value) and does not equal either positive or negative zero.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;sidebar&amp;quot;&amp;gt;&lt;br /&gt;
'''Positive and Negative Zero?'''&lt;br /&gt;
&lt;br /&gt;
This positive-or-negative-zero business is consistent with Java and other specifications, although it seems to fly in the face of common sense. (After all, isn't a number either positive ''or'' negative ''or'' zero? What does it mean when a number is both positive and zero, or both negative and zero?)&lt;br /&gt;
&lt;br /&gt;
In general, the plain-old number 0 is &amp;quot;positive&amp;quot; (but unsigned) zero. Using this in numeric operations with negative numbers can result in what's called &amp;quot;negative&amp;quot; 0; for instance, -2 times 0 equals &amp;quot;negative zero.&amp;quot; The rule is that for multiplication and division, if the operands share the same (perhaps implicit) sign, then the result is positive; otherwise, the result is negative.&lt;br /&gt;
&lt;br /&gt;
In other words, while you may be called upon to know the formal distinction between positive and negative zero, in practice, they're both plain old 0. Also in practice, don't expect to be called upon to know the formal distinction (unless you're taking an exam or writing a spec yourself).&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In discussing the behavior of &amp;lt;tt&amp;gt;boolean( )&amp;lt;/tt&amp;gt; with a string argument, I showed you two expressions that produced the same result. To these two we can now add a third:&lt;br /&gt;
&lt;br /&gt;
 boolean(string-length(&amp;quot;some string&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
The nested call to &amp;lt;tt&amp;gt;string-length( )&amp;lt;/tt&amp;gt; returns a number, which is then passed to &amp;lt;tt&amp;gt;boolean( )&amp;lt;/tt&amp;gt;. If the number passed is 0 — that is, if the string is empty — &amp;lt;tt&amp;gt;boolean( )&amp;lt;/tt&amp;gt; returns false, otherwise true.&lt;br /&gt;
&lt;br /&gt;
'''''When anytype is a node-set.''''' You already know, from the previous chapter, that you can use a location path in a predicate to test for a particular node's existence. For example:&lt;br /&gt;
&lt;br /&gt;
 //employee[emp_address]&lt;br /&gt;
&lt;br /&gt;
selects only those &amp;lt;tt&amp;gt;employee&amp;lt;/tt&amp;gt; elements that have at least one &amp;lt;tt&amp;gt;emp_address&amp;lt;/tt&amp;gt; child.&lt;br /&gt;
&lt;br /&gt;
This form of the predicate is essentially a shortcut for using the &amp;lt;tt&amp;gt;boolean( )&amp;lt;/tt&amp;gt; function with a node-set argument. It returns true if the node-set has at least one member, or false otherwise. That is, the following is equivalent to the short form just presented:&lt;br /&gt;
&lt;br /&gt;
 //employee[boolean(emp_address)]&lt;br /&gt;
&lt;br /&gt;
'''''When anytype is a Boolean value.''''' If &amp;lt;tt&amp;gt;anytype&amp;lt;/tt&amp;gt; is itself a Boolean value, the value returned by &amp;lt;tt&amp;gt;boolean( )&amp;lt;/tt&amp;gt; is identical to the value of &amp;lt;tt&amp;gt;anytype&amp;lt;/tt&amp;gt; itself. If &amp;lt;tt&amp;gt;anytype&amp;lt;/tt&amp;gt; is true, &amp;lt;tt&amp;gt;boolean( )&amp;lt;/tt&amp;gt; returns true; if false, it returns false.&lt;br /&gt;
&lt;br /&gt;
==== not(boolean) ====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;not( )&amp;lt;/tt&amp;gt; function simply flips the value of its passed argument. If the value of &amp;lt;tt&amp;gt;boolean&amp;lt;/tt&amp;gt; is true, &amp;lt;tt&amp;gt;not( )&amp;lt;/tt&amp;gt; returns false and vice versa.&lt;br /&gt;
&lt;br /&gt;
This function is rarely useful in its own right; rather, you pass as an argument some other expression returning a true or false value, enabling &amp;lt;tt&amp;gt;not( )&amp;lt;/tt&amp;gt; to test for the negation of the other expression's value. So you can select all &amp;lt;tt&amp;gt;employee&amp;lt;/tt&amp;gt; elements that do ''not'' have at least one &amp;lt;tt&amp;gt;emp_address&amp;lt;/tt&amp;gt; child using an expression such as:&lt;br /&gt;
&lt;br /&gt;
 //employee[not(emp_address)]&lt;br /&gt;
&lt;br /&gt;
Many comparison operations in XPath look and behave peculiarly, and a particular trap to watch out for when using &amp;lt;tt&amp;gt;not( )&amp;lt;/tt&amp;gt; is how it behaves differently from the &amp;lt;tt&amp;gt;!&amp;lt;/tt&amp;gt; (exclamation point) Boolean operator in comparisons. Consider the following two location paths:&lt;br /&gt;
&lt;br /&gt;
 //employee[@id != &amp;quot;emp1002&amp;quot;]&lt;br /&gt;
 //employee[not(@id = &amp;quot;emp1002&amp;quot;)]&lt;br /&gt;
&lt;br /&gt;
The first example selects all &amp;lt;tt&amp;gt;employee&amp;lt;/tt&amp;gt; element nodes whose &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; attributes' values do not equal &amp;lt;tt&amp;gt;emp1002&amp;lt;/tt&amp;gt; (or that do not have an &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; attribute at all); the second selects all &amp;lt;tt&amp;gt;employee&amp;lt;/tt&amp;gt; element nodes that do not have an &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; attribute whose value is &amp;lt;tt&amp;gt;emp1002&amp;lt;/tt&amp;gt;. If you read those two clauses carefully, you'll realize that the two location paths produce different results when encountering an element such as:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;employee&amp;gt;...&amp;lt;/employee&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;tt&amp;gt;employee&amp;lt;/tt&amp;gt; element ''will not'' be located by the first example, because it has no &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; attribute at all; it ''will'' be located by the second example, though, because it has no &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; attribute with a value of &amp;lt;tt&amp;gt;emp1002&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== true() and false( ) ====&lt;br /&gt;
&lt;br /&gt;
These two Boolean functions are of rather limited utility. You pass them no arguments, and they always return the Boolean value corresponding to their names: &amp;lt;tt&amp;gt;true( )&amp;lt;/tt&amp;gt; always returns the value true, and &amp;lt;tt&amp;gt;false( )&amp;lt;/tt&amp;gt; always returns false. I've found them useful in making explicit — documenting, as it were — the purpose of some other Boolean test. Something like this:&lt;br /&gt;
&lt;br /&gt;
 //book/title[contains(., &amp;quot;XML&amp;quot;) = true(  )]&lt;br /&gt;
&lt;br /&gt;
selects a &amp;lt;tt&amp;gt;book&amp;lt;/tt&amp;gt; element only if the string-value of its &amp;lt;tt&amp;gt;title&amp;lt;/tt&amp;gt; child contains the string &amp;quot;XML.&amp;quot; Including the &amp;lt;tt&amp;gt;= true( )&amp;lt;/tt&amp;gt; doesn't change the test at all, it simply clarifies what you're testing for.&lt;br /&gt;
&lt;br /&gt;
Maybe the most common use of &amp;lt;tt&amp;gt;true( )&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;false( )&amp;lt;/tt&amp;gt;, though, is in XSLT. While I don't want to plunge further here into the details of that language, it's possible to build XSLT-based &amp;quot;subroutines&amp;quot; called ''named templates''. You can pass parameters to a named template in a manner similar to passing arguments to a function; if the named template is driven by parameters whose values it expects to be true or false, the simplest way to pass it either of those values is with the &amp;lt;tt&amp;gt;true( )&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;false( )&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
==== lang(string) ====&lt;br /&gt;
&lt;br /&gt;
Use of this function depends on the use of an &amp;lt;tt&amp;gt;xml:lang&amp;lt;/tt&amp;gt; attribute (either directly, in an instance document, or indirectly, via its DTD). If there is no such attribute in scope at the point of the call to &amp;lt;tt&amp;gt;lang( )&amp;lt;/tt&amp;gt;, the function returns false.&lt;br /&gt;
&lt;br /&gt;
However, if there is such an attribute in scope, &amp;lt;tt&amp;gt;lang( )&amp;lt;/tt&amp;gt; returns true if the context node is &amp;quot;in&amp;quot; the language specified by the string argument passed to it. Consider this code fragment:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;word xml:lang=&amp;quot;EN&amp;quot;&amp;gt;tarradiddle&amp;lt;/word&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Assuming that this element or its text-node child is the context node, the following function call returns true:&lt;br /&gt;
&lt;br /&gt;
 lang(&amp;quot;EN&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
More subtly, &amp;lt;tt&amp;gt;lang( )&amp;lt;/tt&amp;gt; also returns true in a case-''in''sensitive way; you could also use:&lt;br /&gt;
&lt;br /&gt;
 lang(&amp;quot;en&amp;quot;)&lt;br /&gt;
 lang(&amp;quot;En&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
and so on, all of which would return true.&lt;br /&gt;
&lt;br /&gt;
Now, the language codes the &amp;lt;tt&amp;gt;xml:lang&amp;lt;/tt&amp;gt; attribute uses needn't specify major languages only, such as &amp;quot;EN&amp;quot; for English or &amp;quot;DE&amp;quot; for German. They can also specify sublanguages, or language groups, using a hyphen to separate the major language code from the one for the sublanguage. English, for example, can be represented as American English or British English using &amp;lt;tt&amp;gt;xml:lang&amp;lt;/tt&amp;gt; values such as &amp;quot;en-us&amp;quot; and &amp;quot;en-uk.&amp;quot; Suppose the code fragment above specified an &amp;lt;tt&amp;gt;xml:lang&amp;lt;/tt&amp;gt; attribute as follows:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;word xml:lang=&amp;quot;EN-UK&amp;quot;&amp;gt;tarradiddle&amp;lt;/word&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, both of the following would return true:&lt;br /&gt;
&lt;br /&gt;
 lang(&amp;quot;EN&amp;quot;)&lt;br /&gt;
 lang(&amp;quot;en-uk&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The inverse is ''not'' true. Whether &amp;lt;tt&amp;gt;lang( )&amp;lt;/tt&amp;gt; returns true or false, according to the spec, depends on whether the &amp;lt;tt&amp;gt;xml:lang&amp;lt;/tt&amp;gt; value in force for the context node &amp;quot;is the same as or is a sublanguage of the language specified by the argument string.&amp;quot; Thus, if you pass &amp;lt;tt&amp;gt;lang( )&amp;lt;/tt&amp;gt; a string that itself identifies a sublanguage, &amp;lt;tt&amp;gt;lang( )&amp;lt;/tt&amp;gt; will ''not'' return true when the &amp;lt;tt&amp;gt;xml:lang&amp;lt;/tt&amp;gt; value in force is a major language. That is:&lt;br /&gt;
&lt;br /&gt;
 lang(&amp;quot;en-uk&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
returns false when applied to the following code fragment:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;word xml:lang=&amp;quot;EN&amp;quot;&amp;gt;tarradiddle&amp;lt;/word&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Numeric Functions ===&lt;br /&gt;
&lt;br /&gt;
Numeric functions operate on their arguments to produce numeric results. [[XPath and XPointer/XPath Functions and Numeric Operators#xpathpointer-CHP-4-TABLE-4|Table 4-4]] summarizes these functions; each is discussed separately following the table.&lt;br /&gt;
&lt;br /&gt;
Examples in this section refer to the following simple XML document:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;weights&amp;gt;&lt;br /&gt;
    &amp;lt;weight label=&amp;quot;1kg&amp;quot;&amp;gt;1&amp;lt;/weight&amp;gt;&lt;br /&gt;
    &amp;lt;weight label=&amp;quot;2.5kg&amp;quot;&amp;gt;2.5&amp;lt;/weight&amp;gt;&lt;br /&gt;
    &amp;lt;weight label=&amp;quot;1ton&amp;quot;&amp;gt;1016.0469&amp;lt;/weight&amp;gt;&lt;br /&gt;
 &amp;lt;/weights&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;xpathpointer-CHP-4-TABLE-4&amp;quot;&amp;gt;&lt;br /&gt;
'''Table 4-4. Numeric functions'''&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Function prototype !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 number(anytype?)&lt;br /&gt;
| Number || Converts &amp;lt;tt&amp;gt;anytype&amp;lt;/tt&amp;gt; to numeric value&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 sum(nodeset)&lt;br /&gt;
| Number || Returns the sum of all nodes in &amp;lt;tt&amp;gt;nodeset&amp;lt;/tt&amp;gt;, after converting each to a number&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 floor(number)&lt;br /&gt;
| Number || Returns the largest integer that is less than or equal to &amp;lt;tt&amp;gt;number&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 ceiling(number)&lt;br /&gt;
| Number || Returns the smallest integer that is greater than or equal to &amp;lt;tt&amp;gt;number&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 round(number)&lt;br /&gt;
| Number || Returns the integer nearest in value to &amp;lt;tt&amp;gt;number&amp;lt;/tt&amp;gt; (rounds up if number has a decimal portion of .5)&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== number(anytype?) ====&lt;br /&gt;
&lt;br /&gt;
Like the &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;boolean( )&amp;lt;/tt&amp;gt; functions discussed earlier, &amp;lt;tt&amp;gt;number( )&amp;lt;/tt&amp;gt; converts an optional argument to some basic XPath data type — numeric, in this case — based on the data type of the passed argument. If no argument is supplied, the function by default converts the context node's string-value to a number.&lt;br /&gt;
&lt;br /&gt;
'''''When anytype is a string.''''' To be converted to a number, a string argument must consist of optional whitespace, followed by an optional minus sign (&amp;lt;tt&amp;gt;-&amp;lt;/tt&amp;gt;), followed by the numeric value itself, followed by optional whitespace. Any other kind of string is converted to the special value &amp;lt;tt&amp;gt;NaN&amp;lt;/tt&amp;gt;. Note in particular that the string may not include a leading plus sign (&amp;lt;tt&amp;gt;+&amp;lt;/tt&amp;gt;) or formatting characters, such as grouping commas or currency symbols. Among other effects, this also causes &amp;quot;strings&amp;quot; expressing numbers as scientific notation (such as &amp;quot;3.296E3&amp;quot;) to be converted to &amp;lt;tt&amp;gt;NaN&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''''When anytype is a Boolean value.''''' If the Boolean value is true, the value returned by &amp;lt;tt&amp;gt;number( )&amp;lt;/tt&amp;gt; is 1; if false, &amp;lt;tt&amp;gt;number( )&amp;lt;/tt&amp;gt; returns 0. Thus, in this location step:&lt;br /&gt;
&lt;br /&gt;
 weight[number(contains(@label, &amp;quot;kg&amp;quot;))]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;number( )&amp;lt;/tt&amp;gt; returns 1 for both the first and second &amp;lt;tt&amp;gt;weight&amp;lt;/tt&amp;gt; elements, and 0 for the third.&lt;br /&gt;
&lt;br /&gt;
'''''When anytype is a node-set.''''' In this case, the argument is first converted to a string as if it had been passed to the &amp;lt;tt&amp;gt;string( )&amp;lt;/tt&amp;gt; function discussed earlier in this chapter, and then converted to a number according to the rules for converting strings to numbers. This follows common sense; using the sample XML document in this section, for example, this expression:&lt;br /&gt;
&lt;br /&gt;
 number((//weight)[3])&lt;br /&gt;
&lt;br /&gt;
first locates the third &amp;lt;tt&amp;gt;weight&amp;lt;/tt&amp;gt; element in the document, then returns the numeric value 1016.0469.&lt;br /&gt;
&lt;br /&gt;
'''''When anytype is numeric.''''' Passing the &amp;lt;tt&amp;gt;number( )&amp;lt;/tt&amp;gt; function a numeric argument simply returns the value of that argument.&lt;br /&gt;
&lt;br /&gt;
==== sum(nodeset) ====&lt;br /&gt;
&lt;br /&gt;
You can do simple summations across a node-set using the &amp;lt;tt&amp;gt;sum( )&amp;lt;/tt&amp;gt; function; just pass it the node-set in question. Each node is first converted to a number using the rules of conversion laid out for the &amp;lt;tt&amp;gt;number( )&amp;lt;/tt&amp;gt; function, then the summation is performed. We could sum up the values of all the &amp;lt;tt&amp;gt;weight&amp;lt;/tt&amp;gt; elements in the sample document with an expression like:&lt;br /&gt;
&lt;br /&gt;
 sum(//weight)&lt;br /&gt;
&lt;br /&gt;
which would return the value 1 + 2.5 + 1016.0469, or 1019.5469.&lt;br /&gt;
&lt;br /&gt;
Be careful when using &amp;lt;tt&amp;gt;sum( )&amp;lt;/tt&amp;gt; to ensure that you don't run into a not-a-number wall; it takes only a single node with a non-numeric value to make the sum non-numeric as well. Applied to our sample document, this expression:&lt;br /&gt;
&lt;br /&gt;
 sum(//weight/@label)&lt;br /&gt;
&lt;br /&gt;
returns &amp;lt;tt&amp;gt;NaN&amp;lt;/tt&amp;gt;, because not all of the &amp;lt;tt&amp;gt;label&amp;lt;/tt&amp;gt; attributes in the selected node-set are numeric. (''Any'' node failing the numeric test is sufficient to produce a &amp;lt;tt&amp;gt;NaN&amp;lt;/tt&amp;gt; result.)&lt;br /&gt;
&lt;br /&gt;
==== floor(number) and ceiling(number) ====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;floor( )&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ceiling( )&amp;lt;/tt&amp;gt; functions perform similar operations on their arguments. Both return integers nearest in value to that of the argument. For &amp;lt;tt&amp;gt;floor( )&amp;lt;/tt&amp;gt;, the result is the largest integer less than or equal to the argument; for &amp;lt;tt&amp;gt;ceiling( )&amp;lt;/tt&amp;gt;, the smallest integer greater than or equal to the argument. So:&lt;br /&gt;
&lt;br /&gt;
 floor(//weight[3])&lt;br /&gt;
&lt;br /&gt;
returns 1016, while:&lt;br /&gt;
&lt;br /&gt;
 ceiling(//weight[3])&lt;br /&gt;
&lt;br /&gt;
returns 1017.&lt;br /&gt;
&lt;br /&gt;
Note that these are not exactly rounding-down and up functions. Although they consider the fractional part of the passed argument, they simply check that it's greater than 0. If so, &amp;lt;tt&amp;gt;floor( )&amp;lt;/tt&amp;gt; returns the integer portion of the argument and &amp;lt;tt&amp;gt;ceiling( )&amp;lt;/tt&amp;gt;, the integer portion plus 1. If not, &amp;lt;tt&amp;gt;floor( )&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ceiling( )&amp;lt;/tt&amp;gt; both return the same result: the integer portion of the argument.&lt;br /&gt;
&lt;br /&gt;
Be careful when using &amp;lt;tt&amp;gt;floor( )&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ceiling( )&amp;lt;/tt&amp;gt; with negative arguments. A function call like:&lt;br /&gt;
&lt;br /&gt;
 floor(3.2)&lt;br /&gt;
&lt;br /&gt;
returns 3, but:&lt;br /&gt;
&lt;br /&gt;
 floor(-3.2)&lt;br /&gt;
&lt;br /&gt;
returns -4.&lt;br /&gt;
&lt;br /&gt;
==== round(number) ====&lt;br /&gt;
&lt;br /&gt;
Unlike &amp;lt;tt&amp;gt;floor( )&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ceiling( )&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;round( )&amp;lt;/tt&amp;gt; rounds the argument up or down, depending on which direction the nearest integer lies. Thus, the result will always be identical to that of either &amp;lt;tt&amp;gt;floor( )&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;ceiling( )&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 round(//weight[3])&lt;br /&gt;
&lt;br /&gt;
returns 1016, for example (the same result obtained using &amp;lt;tt&amp;gt;floor( )&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
If the fractional part of the passed argument is exactly .5, the &amp;lt;tt&amp;gt;round( )&amp;lt;/tt&amp;gt; function rounds up, consistent with common use (and therefore always behaving just like &amp;lt;tt&amp;gt;ceiling( )&amp;lt;/tt&amp;gt;). So:&lt;br /&gt;
&lt;br /&gt;
 round(//weight[2])&lt;br /&gt;
&lt;br /&gt;
returns 3.&lt;br /&gt;
&lt;br /&gt;
As with &amp;lt;tt&amp;gt;floor( )&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ceiling( )&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;round( )&amp;lt;/tt&amp;gt; can produce unexpected effects when passed a negative argument. (At least, they're unexpected until you think a little about them.)&lt;br /&gt;
&lt;br /&gt;
The calls:&lt;br /&gt;
&lt;br /&gt;
 round(-3.4)&lt;br /&gt;
 round(-3.5)&lt;br /&gt;
 round(-3.8)&lt;br /&gt;
&lt;br /&gt;
Return the values -3, -3, and -4, respectively.&lt;br /&gt;
&lt;br /&gt;
== XPath Numeric Operators ==&lt;br /&gt;
&lt;br /&gt;
XPath includes a set of numeric operators for performing basic arithmetic operations. Don't go looking for net-present-value or square-root operators; they don't exist. But if you simply need to add, subtract, multiply, divide, or find a remainder of two numeric values, here's your answer. [[XPath and XPointer/XPath Functions and Numeric Operators#xpathpointer-CHP-4-TABLE-5|Table 4-5]] summarizes these numeric operators.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;xpathpointer-CHP-4-TABLE-5&amp;quot;&amp;gt;&lt;br /&gt;
'''Table 4-5. XPath numeric operators'''&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Operator !! Description !! Example&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 +&lt;br /&gt;
| Adds two values || &lt;br /&gt;
&lt;br /&gt;
 (//weight)[1] + (//weight)[2]&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 -&lt;br /&gt;
| Subtracts one value from another || &lt;br /&gt;
&lt;br /&gt;
 (//weight)[3] - (//weight)[1]&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 *&lt;br /&gt;
| Multiplies one value times another || &lt;br /&gt;
&lt;br /&gt;
 (//weight)[3] * 5&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 div&lt;br /&gt;
| Divides one value by another || &lt;br /&gt;
&lt;br /&gt;
 (//weight)[3] div 1016.0469&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
&lt;br /&gt;
 mod&lt;br /&gt;
| Returns the remainder after dividing one value by another || &lt;br /&gt;
&lt;br /&gt;
 (//weight)[3] mod 1016.0469&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most of these are straightforward, not requiring any further explanation; however, both the &amp;lt;tt&amp;gt;div&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;mod&amp;lt;/tt&amp;gt; operators could use bit more explanation.&lt;br /&gt;
&lt;br /&gt;
=== div ===&lt;br /&gt;
&lt;br /&gt;
Why use a special &amp;lt;tt&amp;gt;div&amp;lt;/tt&amp;gt; operator at all? Why not just use the more familiar forward slash character, &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;, to divide one value by another?&lt;br /&gt;
&lt;br /&gt;
The answer is that a slash in an XPath expression is already freighted with meaning: it operates as a delimiter between location steps. (A good analogy, in XML terms, might be the required use of entity references, such as &amp;lt;tt&amp;gt;&amp;amp;amp;lt;&amp;lt;/tt&amp;gt; instead of the literal &amp;lt;tt&amp;gt;&amp;lt;&amp;lt;/tt&amp;gt; character.)&lt;br /&gt;
&lt;br /&gt;
=== mod ===&lt;br /&gt;
&lt;br /&gt;
Unlike &amp;lt;tt&amp;gt;div&amp;lt;/tt&amp;gt;, the &amp;lt;tt&amp;gt;mod&amp;lt;/tt&amp;gt; operator is common in other application languages as well as in XPath. The term &amp;quot;mod&amp;quot; comes from modulus or modulo — the formal arithmetic term for the remainder following a division. (Some languages use a single character, like the percent sign, &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt;, to perform the same operation.)&lt;br /&gt;
&lt;br /&gt;
I promised, earlier in this chapter, to show you how to use &amp;lt;tt&amp;gt;mod&amp;lt;/tt&amp;gt; with the &amp;lt;tt&amp;gt;position( )&amp;lt;/tt&amp;gt; function to process every ''n''th node in a given node-set.&lt;br /&gt;
&lt;br /&gt;
The basic idea is first to isolate what ''n'' is, then compare the remainder of dividing a given node's position in the node-set by ''n''. If the remainder is 0, the node in question gets the special &amp;quot;every nth node&amp;quot; processing, otherwise it doesn't.&lt;br /&gt;
&lt;br /&gt;
Suppose we have a list of employees in an XML document, coded something like this (irrelevant details omitted):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;employees&amp;gt;&lt;br /&gt;
    &amp;lt;employee&amp;gt;...&amp;lt;/employee&amp;gt;&lt;br /&gt;
    &amp;lt;employee&amp;gt;...&amp;lt;/employee&amp;gt;&lt;br /&gt;
    &amp;lt;employee&amp;gt;...&amp;lt;/employee&amp;gt;&lt;br /&gt;
    &amp;lt;employee&amp;gt;...&amp;lt;/employee&amp;gt;&lt;br /&gt;
    &amp;lt;employee&amp;gt;...&amp;lt;/employee&amp;gt;&lt;br /&gt;
    &amp;lt;employee&amp;gt;...&amp;lt;/employee&amp;gt;&lt;br /&gt;
 &amp;lt;/employees&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, this document includes six &amp;lt;tt&amp;gt;employee&amp;lt;/tt&amp;gt; elements within the &amp;lt;tt&amp;gt;employees&amp;lt;/tt&amp;gt; container element. If we want to perform some particular operation just for the &amp;lt;tt&amp;gt;employee&amp;lt;/tt&amp;gt; elements in even-numbered positions within the node-set, we could use an XPath expression such as:&lt;br /&gt;
&lt;br /&gt;
 //employee[position(  ) mod 2 = 0]&lt;br /&gt;
&lt;br /&gt;
If we want this operation to occur on every odd-numbered employee in the list, we change the predicate as in this example:&lt;br /&gt;
&lt;br /&gt;
 //employee[position(  ) mod 2 = 1]&lt;br /&gt;
&lt;br /&gt;
If we want to select every third employee, change the 2 in the above examples to 3; for every fourth, change it to 4; and so on.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;mod( )&amp;lt;/tt&amp;gt; function is also useful for certain conversion-type operations, such as converting raw quantities of something to dozens-of-something-plus-leftover-units and four-digit years to their two-digit values. For instance:&lt;br /&gt;
&lt;br /&gt;
 1960 mod 100&lt;br /&gt;
&lt;br /&gt;
returns the value 60.&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</description>
			<pubDate>Fri, 07 Mar 2008 09:45:23 GMT</pubDate>			<dc:creator>Docbook2Wiki</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:XPath_and_XPointer/XPath_Functions_and_Numeric_Operators</comments>		</item>
	</channel>
</rss>