Chapter 5. XPath Functions

  • XPath Function

  • boolean(), ceiling(), concat(), contains last(), local (), count(), false(), floor(), id(), lang(),-name(), name(), namespace-uri(), normalize-space(), not(), number(), position(), round(), starts-with(), string(), string-length(), substring(), substring-after(), substring-before(), sum(), translate(), true()

In Chapter 4 the principles underlying XPath were introduced, but the full value of XPath is limited without functions. Functions provide a “programming” aspect to XPath. Where XPath location paths and patterns are navigational tools, functions are like little programs, they do something. For example, the document() function “goes and gets” another XML instance, similar to an import macro in a word processor.

In the XPath specification, functions are declared with a function prototype, which contains a function name, a function return type, and an argument set. Actually using functions is quite simple, though. Since the processing software maintains a library of functions, you only need a function call to invoke them.

This chapter will describe the functions in the XPath function library,[1] which are divided into groups based on the four object types: node-set, string, Boolean, and number. We will begin by introducing the specific principles and terminology for understanding and explaining functions.

[1] XSLT also has a set of functions described in section 12 of the W3C XSLT specification. These are introduced separately in Chapter 11.

Note that most of the examples in this chapter include the basic XPath expression, followed by an XSLT example that can be used directly in a stylesheet to get a result. XPath expressions do not of themselves return a value in a stylesheet, they must be used within the context of an XSLT attribute, such as match or select. The XSLT element <xsl:value-of> is a good test of the XPath expression and is used in most cases to demonstrate extracting the value of the expression.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.111.9