Appendix : Legacy Presto components : Mashables and Mashups : Mashups in EMML : Writing Mashups in EMML : Declaring Mashup and Macro Variables and Parameters : Variable and Parameter Scopes
Variable and Parameter Scopes
Variables may have a global scope or a local scope. Variables that have a global scope can be used in any statement in the mashup after they have been declared (explicitly or implicitly). Variables with a local scope are only valid within the statement where they are declared or any descendant statements. They are not valid until they have been declared.
If both global and local variables use the same name, the local variable is used within its scope and the global variable is used everywhere else.
Input and output parameters have a global scope when they are declared in <mashup> or <operation>. Parameters declared in <macro> are only valid within the macro itself. Mashups that use macros, however, do have access to the macro result. See Calling a Macro for more information.
Variables declared explicitly in <mashup> or <operation> or declared implicitly by any statement that is a direct child of <mashup> or <operation> have a global scope. Variables declared explicitly within EMML statements or declared implicitly by nested statements have a local scope of that containing statement.
With a mashup such as:
<mashup name="VariableRules"
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" >
<output name="result" type="document"/>

<variables>
<variable name="explicitGlobal" type="string" default="Crichton"/>
</variables>
<assign literal="Ken Scott" outputvariable="implicitGlobal"/>

<display message="main explicitGlobal: " expr="upper-case($explicitGlobal)"/>
<display message="main implicitGlobal: " expr="upper-case($implicitGlobal)"/>

<for variable="i" startCounterValue="1" finalCounterValue="1">
<!-- explicit local variable, hides global variable within for loop -->
<variable name="explicitGlobal" type="string" default="Steig Larsson"/>
<display message="for loop explicitGlobal: "
expr="upper-case($explicitGlobal)"/>

<!-- Updates implicitly created global variable -->
<assign literal="Kathryn Stockett" outputvariable="implicitGlobal"/>
<display message="for loop implicitGlobal: "
expr="upper-case($implicitGlobal)"/>

<assign literal="Ken Scott" outputvariable="implicitLocal"/>
<display message="for loop implicitLocal: "
expr="upper-case($implicitLocal)"/>

<variable name="explicitLocal" type="string" default="Ian M. Banks"/>
<display message="for loop explicitLocal: "
expr="upper-case($explicitLocal)"/>
</for>

<display message="main explicitGlobal:" expr="upper-case($explicitGlobal)"/>
<display message="main implicitGlobal:" expr="upper-case($implicitGlobal)"/>
</mashup>
The debugging messages showing variable states would be:
main explicitGlobal: CRICHTON
main implicitGlobal: KEN SCOTT
for loop explicitGlobal: STEIG LARSSON
for loop implicitGlobal: KATHRYN STOCKETT
for loop implicitLocal: KEN SCOTT
for loop explicitLocal: IAN M. BANKS
main explicitGlobal: CRICHTON
main implicitGlobal: KATHRYN STOCKETT
Copyright © 2013-2017 Software AG, Darmstadt, Germany. (Innovation Release)

Product LogoContact Support   |   Community   |   Feedback