MashZone NextGen 10.2 | Appendix | Legacy Presto components | Mashables and Mashups | Mashups in EMML | Advanced Mashup Techniques | Self-Joins with a Single Dataset
 
Self-Joins with a Single Dataset
Self-joins compare values in repeating nodes from a single result to create the join result. They typically resolve cross references within a single result (one item refers to another item in the same dataset) using the <join> statement.
Note: The example shown in this topic resolves references to the supervisor of employees (the repeating items) that have a supervisor where the supervisors are themselves employees (and thus in that same set of repeating items).
To do this, the join condition for self-joins compare values between repeating items in the same variable. However, EMML join conditions do not support comparisons within a single variable, such as the following join condition:
...
<join outputvariable="result"
joincondition="$staffDoc/employees/employee/supervisor =
$staffDoc/employees/employee/id" >
<select name="employees">
<result>
<employee>{$staffDoc/name/string()}</employee>
<supervisor>{$staffDoc/name/string()}</supervisor>
</result>
</select>
</join>
..
This example selects employees who have a supervisor and joins employee data for that supervisor to the employee’s data using the single $staffDoc variable.
The solution to get a self-join is to copy the single results you want to use in the join condition to a second variable. Then let the join condition compare node values from two different variables.
For example:
<mashup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openmashup.org/schemas/v1.0/EMML/
../schemas/EMMLSpec.xsd"
xmlns="http://www.openmashup.org/schemas/v1.0/EMML"
name="SelfJoin">

<output name="result" type="document"/>

<input name="staffDoc" type="document">
<employees>
<employee>
<id>100</id>
<name>Dmitry</name>
<supervisor>101</supervisor>
</employee>
<employee>
<id>101</id>
<name>Patricia</name>
</employee>
<employee>
<id>102</id>
<name>Blaine</name>
<supervisor>101</supervisor>
</employee>
<employee>
<id>103</id>
<name>Randy</name>
<supervisor>101</supervisor>
</employee>
<employee>
<id>104</id>
<name>Harold</name>
<supervisor>101</supervisor>
</employee>
<employee>
<id>105</id>
<name>Merle</name>
<supervisor>102</supervisor>
</employee>
</employees>
</input>

<!-- duplicate result set in second variable -->
<variable name="staffMirrorDoc" type="document" />
<assign fromvariable="$staffDoc" outputvariable="$staffMirrorDoc" />
<!-- join employee supervisor data to employees -->
<join outputvariable="result"
joincondition="$staffDoc/employees/employee/supervisor =
$staffMirrorDoc/employees/employee/id" >
<select name="employees">
<result>
<employee>{$staffDoc/name/string()}</employee>
<supervisor>{$staffMirrorDoc/name/string()}</supervisor>
</result>
</select>
</join>
</mashup>

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release