The XPath language plays a crucial part in the design of MobileTogether solutions. XPath is used to locate, access, manipulate, generate, and save data in the various data trees used in the design and to define the functioning of different design components. Some important ways in which XPath is used in a MobileTogether design are given below. This overview is intended to give you a broad sense of the flexibility and power of XPath and of how XPath is used in MobileTogether designs.
For more information about XPath, see the XPath 3.1 Recommendation of the W3C, which is the latest version of the language available and is the version supported in MobileTogether Designer. To get you started using a more learning-based approach, see the following:
•Altova's A Gentle Introduction to XPath
•Altova's XPath 3.0 Training
The locator expressions of the XPath language are used to locate nodes in XML trees. A locator expression typically consists of a path that locates the required node. Here are some examples:
•/Company/Office: Locates all Office child elements of the Company element, which is the top-level document node. We know that the Company element is the top-level element because it occurs directly under the root node, which is indicated by the first forward slash.
•/Company/Office: Locates the third Office child element of the Company element.
•/Company/Office/@location: Locates the location attribute of the third Office child element of the Company element.
•//Office[@location='US']: Locates all Office elements that have a location attribute having a value of US.
The list above shows just a few basic locator expressions. There are many more ways in which locator expressions can be constructed.
Operators allow you to apply filters, build conditions, and manipulate selections and data. For example, here are just two operators:
•if (Selection='US') then //Office[@location='US'] else //Office[@location!='US']: This if operator selects US or non-US offices depending on the content of the Selection child element.
•for $i in //Office return $i[@location='US']: This for operator returns all Office elements that have a location attribute having a value of US.
XPath functions enable the manipulation, calculation, and generation of data. For example, a function can take a string as input (the function's argument), and convert into lowercase or even remove a part of the string. The XPath functions that can be used in MobileTogether designs are of the following types:
Global variables contain information about the client mobile device. For example, there is one variable to indicate the device's type, another to indicate its dimensions, and yet another to indicate the device's current orientation (landscape or portrait), and so on. The values of all these variables are obtained at run-time from the client device as part of standard mobile communication procedures. Variables can then be used in XPath/XQuery expressions. As a result, processing can be specified that is conditional upon a device's inherent static properties (such as size) or its changeable dynamic properties (such as orientation).
MobileTogether's global variables are predefined and are listed in the section Global Variables together with each variable's description and possible values. The example below of the MT_iPad global variable (possible values: true(), false()) shows how global variables are called in XPath expressions. The $ symbol is used to indicate that what follows is the name of a global variable, which is the usual way to indicate variables in XPath.
if ( $MT_iPad=true() ) then "Apple" else ""