02.06.2013 Views

XML Demystified

XML Demystified

XML Demystified

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 9 XQuery<br />

You already learned that a function is a task that Saxon-B already knows how to<br />

perform; all you need to do is to call the function in your XQuery whenever you<br />

want Saxon-B to perform that task.<br />

Table 9-2 contains commonly used XQuery functions. You can find a complete<br />

list of functions at www.w3.org/2005/02/xpath-functions.<br />

In addition to calling built-in functions, you can also define your own functions<br />

that can be called the same way a built-in function is called. Here’s what you need<br />

to do. First create the function by writing a function declaration statement.<br />

Function Description Example<br />

upper-case() Converts the argument to<br />

uppercase letters.<br />

lower-case() Converts the argument to<br />

lowercase letters.<br />

upper-case(“Led Zeppelin”)<br />

returns: “LED ZEPPELIN”<br />

lower-case(“Led Zeppelin”)<br />

returns: “led zeppelin”<br />

substring() Returns a substring. substring(“Led Zeppelin”,1, 6)<br />

returns: “Led Ze”<br />

string() Returns the string representation<br />

of the argument.<br />

concat() Returns the concatenation of two<br />

strings.<br />

string-join() Returns a concatenation of the<br />

arguments separated by the<br />

specifi ed separator. The fi rst<br />

argument is a list of strings and the<br />

second argument is the separator.<br />

You may fi nd this particularly<br />

useful for displaying names.<br />

string-length() Returns the length of the string.<br />

If the argument is a node, then<br />

it returns the length of the string<br />

data for that node.<br />

Table 9-2 Commonly Used Built-In XQuery Functions<br />

string(645)<br />

returns: “645” as a string.<br />

concat(“XQu”, “ery”)<br />

returns: “XQuery”<br />

string-join((“Mary”, “Ellen”,<br />

“Smith”), “ “)<br />

returns: “Mary Ellen Smith”<br />

string-length(“Led<br />

Zeppelin”)<br />

returns: 12<br />

141<br />

Functions

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!