Mashups in EMML : Expressions for Mashups : Dynamic XPath or Other Syntax in Mashups
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 or a macro. This may define and use dynamic expressions in a single mashup or macro. Or it can be used to pass dynamic input to another, generic mashup script or generic macro.
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 or macros.
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"/>
This 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"/>
Copyright © 2013-2015 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback