# Generate Document using Multiple Data Sources

DsWord is a Document Solutions product that offers a high performance library to create, load, modify, and save Word documents programmatically.

## Content

You can use multiple data sources with Report Templates to generate Word documents upon template processing. The following example demonstrates how to generate a Word document with the list of car brands followed by the list of car body styles by using two data sources.

1. Define data in two JSON datasources, containing:
    1. A list of some popular car makers
    2. A list of various car body styles
2. Create a new Word document by instantiating the **GcWordDocument** class.
3. Add both datasources with specified data by using **Add** method of the **IDictionary** interface.
4. Add template tags in a paragraph by using **Add** method of the **ParagraphCollection** class.
5. Process the template by using **Process** method and save the final Word document.

    ```csharp
    {
     var makes = "[" +
         "{ \"make\": \"Toyota\" }," +
         "{ \"make\": \"General Motors\" }," +
         "{ \"make\": \"Volkswagen\" }," +
         "{ \"make\": \"Ford\" }," +
         "{ \"make\": \"BMW\" }," +
         "{ \"make\": \"Nissan\" }," +
         "{ \"make\": \"Hyundai\" }," +
         "{ \"make\": \"Honda\" }," +
         "{ \"make\": \"Mazda\" }," +
         "{ \"make\": \"Jaguar\" }," +
         "]";
     var bodyStyles = "[" +
         "{ \"style\": \"Sedan\" }," +
         "{ \"style\": \"Coupe\" }," +
         "{ \"style\": \"Hatchback\" }," +
         "{ \"style\": \"SUV\" }," +
         "{ \"style\": \"Crossover\" }," +
         "{ \"style\": \"Minivan\" }," +
         "{ \"style\": \"Pickup\" }," +
         "{ \"style\": \"Wagon\" }," +
         "]";
    
     var doc = new GcWordDocument();
    
     // Add the data sources
     doc.DataTemplate.DataSources.Add("makes", makes);
     doc.DataTemplate.DataSources.Add("styles", bodyStyles);
    
     // Print the list of some car makes
     doc.Body.Paragraphs.Add("Popular Car Makers", doc.Styles[BuiltInStyleId.Heading2]);
     doc.Body.Paragraphs.Add("{{#makes}}{{makes.make}}{{/makes}}", doc.Styles[BuiltInStyleId.ListBullet]);
    
     // Print the list of car body styles
     doc.Body.Paragraphs.Add("Car Body Styles", doc.Styles[BuiltInStyleId.Heading2]);
     doc.Body.Paragraphs.Add("{{#styles}}{{styles.style}}{{/styles}}", doc.Styles[BuiltInStyleId.ListBullet]);
    
     doc.DataTemplate.Process();
     doc.Save("MultipleDataSources.docx");
    ```

The output of above code will look like below in the Word document:
![Multiple data sources used in GcWord Report Templates](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/multiple-data-sources.png)
**Limitation**
While using different datasources, there may be identical paths (like {{ds1.employee.name}} and {{ds2.employee.name}}). Hence, the fully qualified template tag should be used which includes the name of datasource. The unqualified tags (like {{employee.name}}) will throw an exception.