Altova MobileTogether Designer

Page Sources of the Main Page

Home Prev Top Next

The main page has three page sources: $XML1, $DB1, and $DB2. These are displayed and managed in the Page Sources Pane (see screenshot below).

MTDDBCDataSrcMain01

The XPath context node of the page is the root node $XML1. This means that all XPath expressions on this page have $XML1 as their context node. To locate a node in any of the other trees ($DB1 and $DB2, which are the root nodes of these trees) start the XPath locator path with the respective root node.

 

The first page source: $XML1

This page source was created as an editable empty XML. The root node $XML1 contains a root element (root), which has two attributes (DesiredOffice and DesiredYear). The root node, $XML1, was set (via its context menu) as the XPath context node for the page two. No default file is set, so no data is imported into the tree.

MTDDBCDataSrcXML1

This page source ($XML1) has been created to hold the end user's combo box selections:

 

The DesiredOffice attribute holds the end user's Office selection

The DesiredYear attribute holds the end user's Year selection

 

In order to hold the data selected in the combo boxes, the two attribute nodes are associated with the combo boxes as page source links. Each of the two page source links is made by dragging the attribute node onto the respective comb box (see simulator screenshot below).

MTDDBCSimulatorComboBoxes01

Each of the nodes has been given an initial value when the page loads (via the context menu command Ensure Exists on Load (XPath Value)). This is because the value of the node appears in the associated combo box, and we want the combo box to have an initial selection (see simulator screenshot above). The XPath expressions that provide the initial values are:

 

For @DesiredOffice: if (count($DB1/DB/RowSet/Row) > 0) then $DB1/DB/RowSet/Row[1]/@id else ""
If there is one or more records in $DB1, sets the @id value of the first record as the value of @DesiredOffice. If there is no record, sets the empty string as the value of @DesiredOffice.
 

For @DesiredYear: min(distinct-values($DB2/DB/RowSet/Row[@Office=$XML1/root/@DesiredOffice]/@Year))
In $DB2, selects all the records of the office selected in @DesiredOffice, collects the unique years from these records, and then selects the year with the minimum numerical value.

 

Additionally, we have specified that the @DesiredOffice node is correctly filled whenever the main page loads. This is done with an Update Node action on the OnPageLoad event of the main page (Page | Page Actions).

MTDDBCOnPageLoad

The action updates the @DesiredOffice node. If this is the first loading of the page, then the ID of the first office is passed as the content of @DesiredOffice. Otherwise the value is what is already present in @DesiredOffice. The result of this is that during an execution, the value in @DesiredOffice is not changed, but the value is initialized whenever the page is loaded for the first time.

 

The second page source: $DB1

The second page source ($DB1) is the Offices table in the MS Access database, OfficeSales_DB.mdb. The data for this page source comes from the DB's Office table.

MTDDBCDataSrcDB1

The Offices table has two columns (id and City), which are represented in the data tree as attributes of the Row element, which itself corresponds to a row in the DB table. Since the id column is the primary key and values in it cannot be changed, we cannot edit this column. However, we need to create id values for new rows. We automate this by writing an XQuery expression to generate the id value for every new row that is created. The XQuery expression is inserted by using the context menu command, Ensure Exists on Load (XPath Value):

 

let $all := $DB1/DB/RowSet/Row/@id

let $ids := remove($allindex-of($all""))

let $id := if (empty($ids)) then 1 else max($ids) + 1

return $id

 

Note that the id value is the unique ID number of the office, whereas the City value is the name of the city in which the office is. This is important because while it is the id that is used to uniquely identify an office (via the $XML1/root/@DesiredOffice node), it is the name of the city that we use to identify an office to the end user.

 

An OriginalRowSet node must be created (via the context menu) if any node in the page source is to be edited. This is required so that OriginalRowSet holds the original data while RowSet holds the current (edited) data. The two sets of data (original and edited) are required so that MobileTogether Designer can tell the difference between what is new, updated, and deleted, and can make the necessary changes at the right time. It is also required so that it can create new primary keys with the XQuery let statement. When the database is updated, the updated data becomes the new original data and is entered in the OriginalRowSet node.

 

The third page source: $DB2

The third page source ($DB2) is the Sales table in the MS Access database, OfficeSales_DB1.mdb. The data for this data tree comes from the DB's Sales table.

MTDDBCDataSrcDB2

Each row in the Sales table has five columns (id , Licenses, Month, Year, and Office). The DB table row corresponds to the Row element in the page source tree. The table's columns correspond to the attributes of the Row element. The id attribute has an XQuery expression to generate the id value for every new row that is created. The XQuery expression is inserted by using the context menu command, Ensure Exists before Page Load (XPath Value):

 

let $all := $DB1/DB/RowSet/Row/@id

let $ids := remove($allindex-of($all""))

let $id := if (empty($ids)) then 1 else max($ids) + 1

return $id

 

An OriginalRowSet node must be created (via the context menu) if any node in the page source is to be edited. This is required so that OriginalRowSet holds the original data while RowSet holds the current (edited) data.

 

© 2018-2024 Altova GmbH