Dynamic Mashup Syntax
Dynamic syntax allows you to parameterize the behavior of individual EMML statements. There are four basic techniques you can use:
Using Parameters/Variables in Attributes
You can use parameters or variables directly in attributes for any EMML statement. For example:
<sort inputvariable="$toSort" outputvariable="$sortResult" sortexpr="/records/record" sortkey="key"/> <directinvoke endpoint="$serviceurl" method="get" inputvariables="$opinput" outputvariable="service1Result"/>
Defining XPath or Other Syntax Using <template>
The <template> declaration can be used to dynamically define XPath expressions, portions of XPath expressions, SQL queries or any string. The <template> result is assigned to a variable which can be used in other EMML statements or passed as a parameter to other mashup scripts. See Dynamic XPath or Other Syntax in Mashups for more information.
This example, defines a dynamic join condition, in the expr attribute, based on two input parameters. The result is assigned to a variable and then used in a <join> statement:
<template expr="{$column1} = {$column2}" outputvariable="$dynamicEqualJoin"/>
<join outputvariable="joinResult" joincondition="$dynamicEqualJoin"/>
The next example shows <template> used to build a dynamic SQL query based on input parameters which is then used in a <sql> statement:
<input name="offense" type="string" />
<input name="method" type="string" />
<input name="numrows" type="number" default="10" />
...
<variable name="sqlquery" type="string"
default="select * from crime where 0=0 " />
...
<if condition="$offense != ''">
<template expr="{$sqlquery} and offense = '{$offense}' "
outputvariable="sqlquery"/>
<elseif condition="$method != ''">
<template expr="{$sqlquery} and method = '{$method}' "
outputvariable="sqlquery"/>
</elseif>
</if>
<template expr="{$sqlquery} limit 0,{$numrows}" outputvariable="sqlquery" />
...
<sql name="DCCrime2008" query="$sqlquery" outputvariable="result"/>
Using Dynamic Mashup Expressions Inside XPath Expressions
Dynamic mashup expressions can be used in any portion of XPath expressions - as long as they are not nested. The first example defines an XPath expression to a node by evaluating the $selectedItem variable.
{$selectedItem}[matches(description, 'Ruby')
replace({$fix},{$pattern},{$new})
The second example passes string parameters to the XPath replace() function.
Creating Generic Mashup Scripts
You can also make mashup scripts that are generic. Generic mashup scripts define a pattern of processing that can be applied to different services or conditions based on input paramters. The flow of logic is the same, but what the logic acts on or how the logic is interpreted is dynamic.
Note: if instead you need the flow of logic within a mashup to change dynamically, see Generating Mashup Scripts Dynamically for more information.
Using parameter references in <directinvoke> allows generic mashup scripts to work with many different services. This is the most basic usage for a generic mashup script. To make a mashup generic, though, you typically also have to parameterize expressions for other statements using <template>.
This example shows two simple mashup scripts: 1) the generic script that invokes a service and applies a filter and 2) a mashup that uses the generic mashup as a service to apply to a specific situation.
<mashup name="FilterOneService" ...>
<input name="thisEndpoint" type="string"/>
<input name="thisOp" type="string"/>
<input name="thisFilter" type="string"/>
<output name="filteredResult" type="document"/>
<directinvoke endpoint="$thisEndpoint" method="$thisOp"
outputvariable="$initialResult"/>
<filter inputvariable="$initialResult" filterexpr="$thisFilter"
outputvariable="$filteredResult"/>
</mashup>
The calling mashup defines input parameters using <template> and then invokes the generic mashup script as a component service:
<mashup name="myMashup" ...>
<input name="filterBy" type="string"/>
<variables>
<variable name="myEndpoint" type="string"
default="http://finance.yahoo.com/rss/headline?s=orcl,msft,goog,aapl"/>
<variable name="myOp" type="string" default="GET"/>
</variables>
<output name="myResult" type="document"/>
<template expr="/channel/items/item/{$filterBy}"
outputvariable="$myFilter"/>
<invoke service="FilterOneService" operation="Invoke"
inputparams="myEndpoint,myOp,myFilter"
outputvariable="$myResult"/>
</mashup>
Enterprise Mashup Markup Language (EMML) Documentation is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
