For Each Group

Hi Team,

Please check the attached files.
BI Publisher (59.1 KB)

The attached files have been created using Oracle BI Publisher.
In BI Publisher we have a feature called for-each-group. I searched your documents and forum section, but was unable to find anything related.

Please let me know how can i have a similar output in Aspose.
Let me know if you need more information regarding this.

Thanks and regards


Thanks for contacting support.

As per my understanding, the input RTF file has mail merge fields and then you are filling the data from XML file and finally generating the output in PDF format. Please confirm the requirement so that we can reply accordingly.


I’m not sure about that. But the RTF was generated using Oracle BI Publisher.
Please check the attached image for more info.
BI Publisher Screenshot (113.3 KB)


Thanks for your inquiry. Please check Mail Merge feature of Aspose.Words. It contains support of Foreach Block. Hopefully it will help you to accomplish your requirements. However, if there is any difference in your requirements then please share your input document and expected output document here as ZIP file. We will look into it and will guide you accordingly.

Mail Merge (Aspose.Words)
Foreach Blocks in Mustache Template


Please check the attached image of xml structure.png (90.7 KB) and Expected Output.png (52.1 KB)

Refer to the previous comments attachments for source files.


Thanks for sharing additional information. Please note your template contains Form fields instead of Mail Merge Field or Plain text field. You should change your template to use Mail Merge or LINQ Reporting engine accordingly.

Mail Merge
Nested Mail Merge

LINQ Reporting Engine
LINQ Template Syntax


I generated template using Mail Merge as you specified.
Please check the attached Mail files.
I have also provided how the Expected output should look like.

Also, how do i specify the MAILMERGE TableStart: if there is nested XML as below



Thanks for your inquiry. You can get your desired output by implementing IFieldMergingCallback. Please check following code snippet, hopefully it will help you to accomplish the task.mailmerge_AW179.pdf (19.8 KB)

// Create the Dataset and read the XML.
DataSet testDs = new DataSet();
testDs.ReadXml(@"D:\Downloads\Mail Merge\Mail Merge\test.xml");
string fileName = @"D:\Downloads\Mail Merge\Mail Merge\test.rtf";
// Open the template document.
Document doc = new Document(fileName);
doc.MailMerge.FieldMergingCallback = new HandleMergeFieldHide();
doc.MailMerge.MergeDuplicateRegions = true;
// Trim trailing and leading whitespaces mail merge values
doc.MailMerge.TrimWhitespaces = false;

// Execute the nested mail merge with regions

// Save the output to file
doc.Save(@"D:\Downloads\Mail Merge\Mail Merge\mailmerge_AW179.pdf");
public class HandleMergeFieldHide : IFieldMergingCallback
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
        if (e.FieldName == "SUPERVISOR_NAME")
            if (supervisor == null || supervisor != e.FieldValue.ToString())
                supervisor = e.FieldValue.ToString();
                e.Text = "";


    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)
        // Do nothing.
    private string supervisor = null;


Can you please provide code for Java.


Thanks for your feedback. Please check following Java code for the purpose.

// Create the Dataset and read the XML.
DataSet testDs = new DataSet();
testDs.readXml("D:\\Downloads\\Mail Merge\\Mail Merge\\test.xml");
String fileName = "D:\\Downloads\\Mail Merge\\Mail Merge\\test.rtf";
// Open the template document.
com.aspose.words.Document doc = new com.aspose.words.Document(fileName);
doc.getMailMerge().setFieldMergingCallback(new HandleMergeFieldHide());

// Trim trailing and leading whitespaces mail merge values

// Execute the nested mail merge with regions
// Save the output to file"D:\\Downloads\\Mail Merge\\Mail Merge\\mailmerge_AW179.pdf");


private static class HandleMergeFieldHide implements IFieldMergingCallback {
	public void fieldMerging(FieldMergingArgs e) throws Exception {
		if (e.getFieldName() == "SUPERVISOR_NAME") {
			if (supervisor == null || supervisor != e.getFieldValue().toString())
				supervisor = e.getFieldValue().toString();
	public void imageFieldMerging(ImageFieldMergingArgs e) throws Exception {
		// Do nothing

	private String supervisor = null;


This code is not dynamic right. This would just work for one template.
Doesn’t Aspose support For Each Group like how Oracle BI Publisher supports?


Thanks for your feedback.

I am afraid we are unable to get your point. You have to write code once for any template.

Please note Aspose.Words for Java supports Mail Merge and LINQ Reporting Engine. It does not support Oracle BI Publisher template. As suggested above, you need to change your template for using Aspose.Words for Java Mail Merge or LINQ Reporting Engine feature. Please confirm can we use Oracle BI Publisher template for Mail Merge in MS Word?


You have still not understood my requirement.

FYI, I’m not using Oracle BIP template in Aspose. I’m just asking if you have a similar functionality which i’ve been mentioning from the beginning.

Also, our customers will be creating templates with grouping. It would be good if you guys provide it internally like how Oracle BIP has for-each-group. We can’t write java code for each and every template which they will create.

Let me know if you’re still unable to understand my requirement.


Thanks for your feedback. In addition to nested mail merge, you can also use LINQ Reporting Engine to display sequential data in your document. Please check following LINQ Reporting Engine documentation links hopefully it will serve the purpose.

[Outputting Sequential data(LINQ)]
Typical Templates