Bookmark and Share Share

Dynamic Mashup Expressions

Dynamic mashup expressions provide dynamic content in a mashup script. You can use dynamic mashup expressions:

  • In literal XML: to define the data to fill the mashup result, variable or parameter that is being constructed. See Dynamic Expressions in Literal XML for examples

  • In any XPath expression or EMML attribute that accepts an XPath expression: This can replace the entire XPath expression or any part of the XPath expression.

    Note: you cannot nest dynamic mashup expressions. So you cannot use a dynamic mashup expression in an XPath inside a dynamic mashup expression for literal XML.

    This can be useful to make any EMML statement dynamic including macros. See Dynamic Expressions in XPath Expressions and <macro> for examples.

  • In <template> elements to build syntax or any string dynamically: This is commonly done to build a dynamic expression to use as input parameters for a generic mashup script. But you can use the <template> element to build any string dynamically within a mashup script. See Dynamic XPath or Other Syntax in Mashups for examples.

  • In <constructor> or <appendresult>: with XQuery expressions. See Using XQuery Expressions in Construction Commands for examples.

Dynamic expressions are XPath expressions enclosed in braces ( { expression } ). Variable references start with $ in dynamic mashup expressions. For example:

{$filterResult/list/name} 
{upper-case($list/memberName)} 
{$selectedItem}[matches(description, 'Ruby') 
Hello, my name is {$currentUser}!]

Dynamic Expressions in Literal XML

Variable or parameter declarations and mashup statements that define the structure of the result returned by that statement can include the literal XML structure of the content and literal data. These statements can also use dynamic mashup expressions to define the data that should fill this literal structure dynamically.

For example:

<constructor outputvariable="$result"> 
    <res:mailingList> 
      <res:displayName>{$filterResult/list/name}</res:displayName> 
      <res:email>{$filterResult/list/email}</res:email> 
      <res:greet>Hello {$filterResult/list/name}, </res:greet> 
    </res:mailinglist> 
</constructor>

Mashup expressions can also contain XPath functions or predicates, such as this example:

<appendresult outputVariable="$result"> 
  <res:member> 
    <res:name>{upper-case($list/memberName)}</res:name> 
    ... 
  </res:member> 
</appendresult>

These dynamic expression can use XQuery expressions instead of XPath for more complicated construction scenarios such as iterating through several variables or using sorting. See Using XQuery Expressions in Construction Commands.

Dynamic Expressions in XPath Expressions

XPath expressions used in a mashup script can contain dynamic mashup expressions. This allows the behavior of the mashup script to be dynamic based on input parameters.

This is commonly done for parameterized mashup scripts where the component services that are executed are defined dynamically with input parameters. In these generic mashups, the XPath expressions that should be used in commands may need to change based on the component services.

In the example shown below, the path that defines the nodes to use in a <filter> command is defined in a variable named selectediItem. The variable must be resolved first, to get the full XPath expression to use for filtering.

<filter outputvariable="$result" 
  filterexpr="{$selectedItem}[matches(title, $feedfilter)]"/>

This next example also shows a filter where only a portion of the XPath that selects nodes is from a dynamix mashup expression:

<filter outputvariable="$result" 
  filterexpr="$documents/product/{$version}/]"/>

Dynamic expressions can also be passed from a <template> declaration. For example:

<template expr="{$selectedItem}[matches(title, $feedfilter)]" 
  outputvariable="inputFilter"/> 
<filter outputvariable="$result" filterexpr="$inputFilter"/>