Nested foreach Block

Hi,

Is there a way for aspose word to understand nested foreach loop.and how to create the nested foreach block in a word template.

I have a class model that has nested structure, I am not able to get expected output, pls let me know if my word template is not correct. which it is showing below


public class country
{
public string countryName{get;set;}
public int countryID{get;set;}
List states{get;set;}
}


public class state
{
public string stateName{get;set;}
public int stateID{get;set;}
List cities{get;set;}
}


public class city
{
public string cityName{get;set;}
public int cityID{get;set;}
public long cityPopulation{get;set;}
}

Word Template


{{TableStart:country}}

CountryName:{{countryName}}

CountryID:{{countryID}}

{{#foreach state}}

StateName:{{stateName}}

StateID{{stateID}}

{{#foreach city}}

CityName:{{cityName}}

CityID:{{cityID}}

CityPopulation{{cityPopulation}}

{{/foreach city}}

{{/foreach state}}

{{TableEnd:country}}


expected output


CountryName: USA
CountryID:1

StateName:Connecticut
StateID:1

CityName:New Haven
CityID:1
CityPopulation:200000

CityName:BridgePort
CityID:2
CityPopulation:…

CityName:…
CityID:…
CityPopulation:…

StateName:Ohio
StateID:2

CityName:columbus
CityID:1
CityPopulation:200000

CityName:…
CityID:…
CityPopulation:…

@Nicksha256,

Thanks for your inquiry. To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • Sample XML file containing the data to build report from
  • Aspose.Words generated output DOCX file showing the undesired behavior
  • Your expected DOCX Word document. You can create expected document by using Microsoft Word.
  • Please also create a standalone simple console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. Please do not include Aspose.Words.dll files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you code to achieve the same by using Aspose.Words. Thanks for your cooperation.