We looked at Contexts in the article Aggregate Functions, but it's worth examining this transform again in a little more detail in order to better understand the concept of contexts. It is a good idea to step through the transform using F11 as you follow the description and also experiment with changing the Sum.Context input and look at the different results produced.
|Liquid Data Mapper - Contexts|
The output of the transform is a CSV with two columns ‘Store’ and ‘Total Assets’. When the transform runs it reads the XmlReader.Bookstore items, and creates a CsvWriter.Row from each XmlReader.Bookstore entry returned. So the CsvWriter.Row is in the context of the current XmlReader.Bookstore.
Next the mapper reads XmlReader.Bookstore.Name and creates a CsvWriter.Store item. This action is made within the context of the parent CsvWriter.Row, so the CsvWriter.Store value comes from XmlReader.Bookstore.Name using the current XmlReader.Bookstore.
Next the Sum.Result value is requested. The Sum will produce a Sum.Result for each value read from Sum.Context. The Sum.Context points to XmlReader.Bookstore, which is in context, so the Sum evaluates all the Sum.Value items within the Sum.Context. (i.e. the current XmlReader.Bookstore).
The values come from the Multipy.Result, which is calculated by evaluating Multipy.Value1 and Multipy.Value2. An implied context is created for the parent nodes XmlReader.StockItem and XmlReader.Stock so when XmlReader.price and XmlReader.quantity are read they are both taken from the same XmlReader.StockItem.
We can examine the output window for a trace describing what actions will be performed.
0001  : WriterTextFileDocument(file:02, data:03)
0002  : Constant(..\..\Output\Agregate Functions 01.csv:String)
0003  : WriteTextFileRow(file:01, value:04)
0004  : ReadChildItems(source:05, nodeType:Bookstore (Node))
0005  : XmlRootNode(xmlDocument:06, nodeType:Company (Node))
0006  : XmlFileReader(filename:07)
0007  : Constant(..\..\Data Files\CompanyData.xml:String)
0008  : WriterTextFileColumn(file:01, type:Store (String?), value:09)
0009  : ReadChildItems(source:10, nodeType:Name (String))
0010  : ReferenceTo(04)
0011  : WriterTextFileColumn(file:01, type:Total Assets (String?), value:12)
0012  : SumFunction(Ctx:13, value:14)
0013  : ReferenceTo(04)
0014  : MultiplyFunction(value 1:15, value 2:19)
0015  : ReadChildItems(source:16, nodeType:price (Double))
0016  : ReadChildItems(source:17, nodeType:StockItem (Node))
0017  : ReadChildItems(source:18, nodeType:Stock (Node))
0018  : ReferenceTo(04)
0019  : ReadChildItems(source:20, nodeType:quantity (Int32))
0020  : ReferenceTo(16)
A breakdown of this trace is included in the help.
Tip: Execute the transform by pressing Shift-F5. Debug the transform by pressing F5 to start the debugger, then:
F11 - Step Into
F9 - Set break point
F5 - Run (stops on break points)
A free trial of the Liquid Data Mapper is available from: