We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Looking for advise on having a field in the output only if it is present in the input xml

To describe the problem with an example,
if my input xml is


Note Description is optional in ‘Item’.

and template doc looks like

{{#foreach Item}}

{{/foreach Item}}

Want to exclude


from the output if ‘Item’ does not have ‘Description’ element.

Assuming achievable using the ‘IF’
Looking for an example that will do the job. Thanks.


Do you want to use LINQ Reporting Engine or the regular Mail Merge and Reporting feature of Aspose.Words for .NET?

In case of regular Mail Merge, you can get idea from the if-else ‘Mustache’ template syntax example, please see the sample input, output documents and screenshot in this archive (Mustache-Template-Syntax.zip (38.5 KB)) and try running the following code:

Document doc = new Document("E:\\Mustache-Template-Syntax\\input.docx");
doc.MailMerge.UseNonMergeFields = (true);
doc.MailMerge.Execute(new String[] { "GENDER" }, new Object[] { "MALE" });

Hope, this helps in achieving what you are looking for.

Managing adding a field and having a ‘IF’ for it. Does the job. Thanks


It is great that you were able to find what you were looking for. Please let us know any time you have any further queries.