Processing Collections with Extended Binding


Scenario

We want to display an extract of a user's purchases of the last two months in a document. The data required for this is already supplied from a specialist application as a valid connect file:

<OneOffixxConnectBatch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schema.oneoffixx.com/OneOffixxConnectBatch/1"> <Settings> <Add key="CreateConnectorResult">true</Add> </Settings> <Entries> <OneOffixxConnect> <Arguments> <LanguageLcid>1031</LanguageLcid> <TemplateId>2e221a62-c9ec-4f4d-89d5-b0919c249867</TemplateId> </Arguments> <Function name="CustomInterfaceConnector" id="70E94788-CE84-4460-9698-5663878A295B"> <Arguments> <Interface Name="PurchaseInterface"> <Customer> <CustomerNumber>974853</CustomerNumber> <Name>Buyer</Name> <FirstName>Brian</FirstName> </Customer> <Purchases> <Purchase> <Id>927859198.123</Id> <Date>10.12.2019</Date> <Payment>Paid</Payment> <Delivery>Delivered</Delivery> <Amount>120.10</Amount> </Purchase> <Purchase> <Id>1234539198.527</Id> <Date>15.01.2020</Date> <Payment>Paid</Payment> <Delivery>Delivered</Delivery> <Amount>230.55</Amount> </Purchase> <Purchase> <Id>456454198.527</Id> <Date>15.01.2020</Date> <Payment>Paid</Payment> <Delivery>Delivered</Delivery> <Amount>15.55</Amount> </Purchase> <Purchase> <Id>877906786.527</Id> <Date>18.01.2020</Date> <Payment>Pending</Payment> <Delivery>Delivered</Delivery> <Amount>145.80</Amount> </Purchase> <Purchase> <Id>9678567.527</Id> <Date>09.02.2020</Date> <Payment>Pending</Payment> <Delivery>Pending</Delivery> <Amount>20.90</Amount> </Purchase> </Purchases> </Interface> </Arguments> </Function> </OneOffixxConnect> </Entries> </OneOffixxConnectBatch>

Since we do not know how many entries have to be mapped in the document, it is not possible to build the template statically. Therefore, we need an extended binding and a collection.


Definition of the collection in the interface definition

The first thing to do is to create the Connect interface definition:

<InterfaceDescription Name="PurchaseInterface"> <!-- Evaluation of the data for <Customer></Customer> --> <Node Id="PurchaseInterface.Customer.Name" XPath="./Customer/Name">[Customer Name]</Node> <Node Id="PurchaseInterface.Customer.FirstName" XPath="./Customer/FirstName">[Customer Firstname]</Node> <Node Id="PurchaseInterface.Customer.CustomerNumber" XPath="./Customer/CustomerNumber">[Customer Number]</Node> <!-- Evaluation of the data for <Purchases></Purchases> --> <NodeCollection Id="PurchaseInterface.Purchases" XPath="./Purchases/Purchase"> <Node Id="PurchaseInterface.Purchase.Id" XPath="./Id">[Puchase Id]</Node> <Node Id="PurchaseInterface.Purchase.Date" XPath="./Date">[Puchase Date]</Node> <Node Id="PurchaseInterface.Purchase.Payment" XPath="./Payment">[Pending]</Node> <Node Id="PurchaseInterface.Purchase.Delivery" XPath="./Delivery">[Pending]</Node> <Node Id="PurchaseInterface.Purchase.Amount" XPath="./Amount">[Amount]</Node> </NodeCollection> </InterfaceDescription>

Running the Connect file now results in the following data in the CustomXML part:

<Interfaces windowwidth="0" windowheight="0" minwindowwidth="0" maxwindowwidth="0" minwindowheight="0" maxwindowheight="0"> <NodeGroup id="PurchaseInterface" row="0" column="0" columnspan="0" label="PurchaseInterface" visible="True"> <Text id="PurchaseInterface.Customer.Name" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Customer.Name" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[Buyer]]></Text> <Text id="PurchaseInterface.Customer.FirstName" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Customer.FirstName" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[Brian]]></Text> <Text id="PurchaseInterface.Customer.CustomerNumber" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Customer.CustomerNumber" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[974853]]></Text> <Collection id="PurchaseInterface.Purchases"> <Element> <Text id="PurchaseInterface.Purchase.Id" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Id" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[927859198.123]]></Text> <Text id="PurchaseInterface.Purchase.Date" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Date" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[10.12.2019]]></Text> <Text id="PurchaseInterface.Purchase.Payment" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Payment" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[Bezahlt]]></Text> <Text id="PurchaseInterface.Purchase.Delivery" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Delivery" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[Geliefert]]></Text> <Text id="PurchaseInterface.Purchase.Amount" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Amount" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[120.10]]></Text> </Element> <Element> <Text id="PurchaseInterface.Purchase.Id" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Id" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[1234539198.527]]></Text> <Text id="PurchaseInterface.Purchase.Date" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Date" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[15.01.2020]]></Text> <Text id="PurchaseInterface.Purchase.Payment" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Payment" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[Bezahlt]]></Text> <Text id="PurchaseInterface.Purchase.Delivery" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Delivery" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[Geliefert]]></Text> <Text id="PurchaseInterface.Purchase.Amount" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Amount" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[230.55]]></Text> </Element> <Element> <Text id="PurchaseInterface.Purchase.Id" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Id" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[1234539198.527]]></Text> <Text id="PurchaseInterface.Purchase.Date" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Date" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[15.01.2020]]></Text> <Text id="PurchaseInterface.Purchase.Payment" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Payment" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[Bezahlt]]></Text> <Text id="PurchaseInterface.Purchase.Delivery" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Delivery" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[Geliefert]]></Text> <Text id="PurchaseInterface.Purchase.Amount" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Amount" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[15.55]]></Text> </Element> <Element> <Text id="PurchaseInterface.Purchase.Id" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Id" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[1234539198.527]]></Text> <Text id="PurchaseInterface.Purchase.Date" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Date" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[18.01.2020]]></Text> <Text id="PurchaseInterface.Purchase.Payment" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Payment" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[Ausstehend]]></Text> <Text id="PurchaseInterface.Purchase.Delivery" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Delivery" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[Geliefert]]></Text> <Text id="PurchaseInterface.Purchase.Amount" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Amount" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[145.80]]></Text> </Element> <Element> <Text id="PurchaseInterface.Purchase.Id" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Id" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[1234539198.527]]></Text> <Text id="PurchaseInterface.Purchase.Date" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Date" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[09.02.2020]]></Text> <Text id="PurchaseInterface.Purchase.Payment" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Payment" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[Ausstehend]]></Text> <Text id="PurchaseInterface.Purchase.Delivery" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Delivery" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[Ausstehend]]></Text> <Text id="PurchaseInterface.Purchase.Amount" row="0" column="0" columnspan="0" multiline="False" multilinerows="3" locked="False" label="PurchaseInterface.Purchase.Amount" readonly="False" visible="True" required="False" regex="" validationmessage="" tooltip="" tracked="False"><![CDATA[20.90]]></Text> </Element> </Collection> </NodeGroup> </Interfaces>

The next step is to bring the content of the NodeGroup into the document. For Name, FirstName and CustomerNumber this can be done normally via the editor. From the following screenshot you can also see that the nodes of the collection are also available.

 

But: Since we have five possible values for a NodeId, these cannot be inserted just like that. If these nodes are inserted directly in the document, then the resulting document would look like this:


The Extended Binding

All entries are missing except the first one. This can only be solved with an extended Binding:

<w:sdtContent xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> <!-- Durchgehen aller Element-Nodes der Collection mit Id 'PurchaseInterface.Purchases' --> <xsl:for-each select="//Collection[@id='PurchaseInterface.Purchases']/Element"> <!-- Ein Paragraph für jedes Element --> <w:p w14:paraId="570C6751" w14:textId="2D5561B9" w:rsidR="00957F5A" w:rsidRPr="008A2A05" w:rsidRDefault="00AE649F" w:rsidP="00F7144B" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"> <w:pPr> <w:tabs> <w:tab w:val="left" w:pos="1985" /> <w:tab w:val="left" w:pos="3969" /> <w:tab w:val="left" w:pos="5529" /> <w:tab w:val="left" w:pos="7371" /> </w:tabs> <w:rPr> <w:lang w:val="de-DE" /> </w:rPr> </w:pPr> <w:r w:rsidR="00957F5A" w:rsidRPr="008A2A05"> <w:rPr> <w:lang w:val="de-DE" /> </w:rPr> <w:t> <!-- Auslesen des Wertes für Text mit id 'PurchaseInterface.Purchase.Id' im aktuellen Element (.) --> <xsl:value-of select="./Text[@id='PurchaseInterface.Purchase.Id']" /> </w:t> </w:r> <w:r w:rsidR="00957F5A" w:rsidRPr="008A2A05"> <w:rPr> <w:lang w:val="de-DE" /> </w:rPr> <w:tab /> </w:r> <w:r w:rsidR="00957F5A" w:rsidRPr="008A2A05"> <w:rPr> <w:lang w:val="de-DE" /> </w:rPr> <w:t> <!-- Auslesen des Wertes für Text mit id 'PurchaseInterface.Purchase.Date' im aktuellen Element (.) --> <xsl:value-of select="./Text[@id='PurchaseInterface.Purchase.Date']" /> </w:t> </w:r> <w:r w:rsidR="00771635" w:rsidRPr="008A2A05"> <w:rPr> <w:lang w:val="de-DE" /> </w:rPr> <w:tab /> </w:r> <w:r w:rsidR="00957F5A" w:rsidRPr="008A2A05"> <w:rPr> <w:lang w:val="de-DE" /> </w:rPr> <w:t> <!-- Auslesen des Wertes für Text mit id 'PurchaseInterface.Purchase.Payment' im aktuellen Element (.) --> <xsl:value-of select="./Text[@id='PurchaseInterface.Purchase.Payment']" /> </w:t> </w:r> <w:r w:rsidR="00771635" w:rsidRPr="008A2A05"> <w:rPr> <w:lang w:val="de-DE" /> </w:rPr> <w:tab /> </w:r> <w:r w:rsidR="00957F5A" w:rsidRPr="008A2A05"> <w:rPr> <w:lang w:val="de-DE" /> </w:rPr> <w:t> <!-- Auslesen des Wertes für Text mit id 'PurchaseInterface.Purchase.Delivery' im aktuellen Element (.) --> <xsl:value-of select="./Text[@id='PurchaseInterface.Purchase.Delivery']" /> </w:t> </w:r> <w:r w:rsidR="00F7144B" w:rsidRPr="008A2A05"> <w:rPr> <w:lang w:val="de-DE" /> </w:rPr> <w:tab /> </w:r> <w:r w:rsidR="00957F5A" w:rsidRPr="008A2A05"> <w:rPr> <w:lang w:val="de-DE" /> </w:rPr> <w:t> <!-- Auslesen des Wertes für Text mit id 'PurchaseInterface.Purchase.Amount' im aktuellen Element (.) --> <xsl:value-of select="./Text[@id='PurchaseInterface.Purchase.Amount']" /> </w:t> </w:r> </w:p> </xsl:for-each> </w:sdtContent>

 

With this extended binding the document looks like this after generation

 

PrimeSoft AG, Bahnhofstrasse 4, 8360 Eschlikon, Switzerland