1. Problem
You need to create a repeating
structure in an output document with no equivalent repeating structure
in an input document.
2. Solution
BizTalk Sever provides
two functoids, the Table Looping functoid and the Table Extractor
functoid, for creating a repeating node structure from a flattened input
structure, from constant values, and from the output of other
functoids. The Table Looping functoid is used to create a table of
information based on inputs. The functoid will generate output for each
row from this table. The Table Extractor functoid is used to direct data
from each column in the table to a node in the destination document.
Following are the basic steps for configuring these functoids.
Click
the Toolbox, and then click the Advanced Functoids tab. Drag the
functoid onto the map surface, and create links to the functoid.
Set
the first input parameter, which is a link from a node structure in the
input document that defines the scope of the table. If this node
repeats in the input document, the number of occurrences of this element
in the input document will be used to control the number of times the
set of Table Extractor functoids will be invoked at runtime.
Set
the second input parameter, which is a constant that defines the number
of columns for each row in the table.
Set
the next input parameters, which define the inputs that will be placed
in the table. These inputs can come from the input document, the output
from other functoids, constant values, and so on.
Configure
the table based on inputs for the Table Looping functoid.
Select
the ellipsis next to the TableFunctoidGrid
property in the Properties window to launch the Table Looping
Configuration dialog box.
For each cell, select
a value from the drop-down list. The drop-down list will contain a
reference to all of the inputs you defined in step 1c.
Check
or uncheck the Gated check box. If checked, column 1 will be used to
determine whether a row in the table should be processed as follows:
When the value in column 1 of the row is the output from a logical
functoid, if the value is True, the row is
processed, and if the value is False,
the row is not processed. Similarly, if the value in column 1 of the
row is from a field, the presence of data equates to True, and the row is processed, and the absence of data
equates to False, and the row is
not processed and subsequently missing from the output structure.
Select OK to close the dialog box.
Configure the outputs
for the Table Looping functoid.
Link the Table Looping
functoid to the repeating node structure in the output document.
Link
the Table Looping functoid to a Table Extractor functoid for each
column in the table. The Table Extractor functoid can be found in the
Toolbox on the Advanced Functoids tab.
Configure the input parameters for each Table Extractor
functoid.
Set the first input parameter,
which is the output link from the Table Looping functoid.
Set
the second input parameter, which is the column number of the data to
be extracted from the table.
Configure
the outputs for each Table Extractor functoid. Link the functoid to a
node in the destination schema that is part of a repeating structure.
NOTE
It is very helpful to
label all of the links so that meaningful names are displayed when
configuring these functoids.
3. How It Works
The Table Looping and Table
Extractor functoids are used together. As an example, suppose that you
have the sample input document shown in Listing 1.
Example 1. Flattened Input Structure
<AliasesFlat> <Names> <Alias1FirstName>John</Alias1FirstName> <Alias1LastName>Doe</Alias1LastName> <Alias2FirstName>Sam</Alias2FirstName> <Alias2LastName>Smith</Alias2LastName> <Alias3FirstName>James</Alias3FirstName> <Alias3LastName>Jones</Alias3LastName> </Names> </AliasesFlat>
|
The goal is to use these two
functoids to create an output document of the format shown in Listing 2.
Example 2. Repeating Nested Structure
<AliasesRepeating> <AliasNames> <FirstName>John</FirstName> <LastName>Doe</LastName> </AliasNames> <AliasNames> <FirstName>Sam</FirstName> <LastName>Smith</LastName> </AliasNames> <AliasNames> <FirstName>James</FirstName> <LastName>Jones</LastName> </AliasNames> </AliasesRepeating>
|
Figure 1 shows the configuration for the input parameters
for the Table Looping functoid. The first parameter is a reference to
the node structure Names in the
input schema. The second parameter is a constant value of 2 indicating there will be two columns in the table.
The remaining parameters are the first and last name of each alias from
the input document.
Figure 2 shows the completed Table
Looping Configuration dialog box for the Table Looping functoid. It has
been configured so that each row contains an alias first name in column 1
and an alias last name in column 2. There will be three rows in the
table to process, one for each alias provided as input.
The output links from the
Table Looping functoid are configured as follows:
An output link to the
AliasNames repeating node structure in
the destination schema
An
output link to a Table Extractor functoid for processing first names
(column 1) from the table
An output link to a Table
Extractor functoid for processing last names (column 2) from the table
Figure
3 shows the configuration for the Table
Extractor functoid that will process column 1 from the table. The first
parameter is a link from the Table Looping functoid, and the second
parameter is a constant value of 1,
which indicates it will process the first column from each row as it is
processed.
Figure 4 shows the configuration for the Table
Extractor functoid that will process column 2 from the table. The first
parameter is a link from the Table Looping functoid, and the second
parameter is a constant value of 2,
which indicates it will process the second column from each row as it is
processed.
Finally, each Table Extractor
functoid must be linked to a node in the destination schema. The
complete map is shown in Figure 5.
Here is what the data table
will look like when the map is processed:
Column 1 | Column 2 |
---|
John | Doe |
Sam | Smith |
James | Jones |
Once the table is loaded, it
will generate three sets of output: one set of output for each row in
the table. This, in turn, will create three repetitions of the AliasNames node structure in the destination
document: one for each row in the table. A repeating node structure has
been created, even though one did not exist in the input document.