Dynamic XPath or Other Syntax in Mashups
You can use the <template> declaration to create XPath expressions, SQL queries or other syntax strings dynamically for any use in a mashup. This may define dynamic expressions within one mashup or it can be used to pass dynamic input to another, generic mashup script.
You define the syntax string you want with one or more dynamic mashup expressions in the expr attribute for <template>. This expression is evaluated at runtime and the result is assigned to the variable you identify in the outputvariable attribute.
The output variable can then be used in other EMML statements or passed as an input parameter to other mashups.
Examples
The example shown below defines an expression for a join condition. In this case, $column1 and $column2 are input parameters that contain the XPath expressions to the columns to use in the join. This allows the subsequent <join> statement to be dynamic based on user inputs.
<template expr="{$column1} = {$column2}" outputvariable="$dynamicEqualJoin"/>
<join outputvariable="$joinResult" joincondition="$dynamicEqualJoin"/>
The next example shows <template> used to define sort keys:
<template expr="{$key}/@id" outputvariable="$dynamicIdSort"/>
<sort inputvariable="$toSort" outputvariable="$sortResult"
sortexpr="/records" sortkey="$dynamicIdSort"/>
The final example shows <template> used to construct a SQL query:
<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"/>
Enterprise Mashup Markup Language (EMML) Documentation is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
