I am attempting to insert a table based on XML from a datasource. I want this XML to enter as a single merge field that will be provided alongside other merge fields. I am working with the restriction that the merge document must be one row to one document.
A sample of possible XML is below;
<?xml version="1.0" encoding="utf-8"?>
<PaymentPlanInstalments>
<Instalment Number="1" Date="2018-12-04" Amount="10"></Instalment>
<Instalment Number="2" Date="2018-12-05" Amount="20"></Instalment>
<Instalment Number="3" Date="2018-12-06" Amount="30"></Instalment>
</PaymentPlanInstalments>
I have managed to get a proof of concept working using /INCLUDETEXT with the XML above saved in a file using the below xsl formatting stylesheet
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:processing-instruction name="mso-application">
<xsl:text>progid="Word.Document"</xsl:text>
</xsl:processing-instruction>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" w:macrosPresent="no" w:embeddedObjPresent="no" w:ocxPresent="no">
<w:body>
<wx:sect>
<w:tbl>
<w:tblPr>
<w:tblW w:w="0" w:type="auto" />
</w:tblPr>
<w:tblGrid>
<w:gridCol w:w="4000" />
<w:gridCol w:w="4000" />
<w:gridCol w:w="4000" />
</w:tblGrid>
<w:tr>
<w:trPr>
<w:tblHeader />
</w:trPr>
<w:tc>
<w:tcPr>
<w:tcW w:w="4000" w:type="dxa" />
<w:shd w:val="clear" w:color="auto" w:fill="auto" />
</w:tcPr>
<w:p>
<w:r>
<w:t>Instalment Number</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="4000" w:type="dxa" />
<w:shd w:val="clear" w:color="auto" w:fill="auto" />
</w:tcPr>
<w:p>
<w:r>
<w:t>Instalment Date</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="4000" w:type="dxa" />
<w:shd w:val="clear" w:color="auto" w:fill="auto" />
</w:tcPr>
<w:p>
<w:r>
<w:t>Instalment Amount</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
<xsl:for-each select="//PaymentPlanInstalments/Instalment">
<w:tr>
<w:tc>
<w:tcPr>
<w:tcW w:w="4000" w:type="dxa" />
<w:shd w:val="clear" w:color="auto" w:fill="auto" />
</w:tcPr>
<w:p>
<w:r>
<w:t>
<xsl:value-of select="@Number" />
</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="4000" w:type="dxa" />
<w:shd w:val="clear" w:color="auto" w:fill="auto" />
</w:tcPr>
<w:p>
<w:r>
<w:t>
<xsl:value-of select="@Date" />
</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="4000" w:type="dxa" />
<w:shd w:val="clear" w:color="auto" w:fill="auto" />
</w:tcPr>
<w:p>
<w:r>
<w:t>
<xsl:value-of select="@Amount" />
</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
</xsl:for-each>
</w:tbl>
<w:p />
<w:sectPr>
<w:pgSz w:w="11906" w:h="16838" />
<w:pgMar w:top="1417" w:right="1417" w:bottom="1134" w:left="1417" w:header="708" w:footer="708" w:gutter="0" />
<w:cols w:space="708" />
<w:docGrid w:line-pitch="360" />
</w:sectPr>
</wx:sect>
</w:body>
</w:wordDocument>
</xsl:template>
</xsl:stylesheet>
This produces the following table (apologies I was sent here from stack overflow and do not have 10 rep to embed images)
https://i.sstatic.net/HBhGJ.png
The underlying include text appears as such:
{INCLUDETEXT sample.xml \c XML \t sample2.xsl}
Please note sample.xml and sample2.xsl are stored in the same directory as the word document and contain the above data and formatting rules.
The issue I am running into however is once I add the XML to a merge field record I can no longer apply an XSL Transformation.
Is this possible using Mailmerge functionality?
If it is impossible to apply XSL formatting to a merge field are their any other solutions people have to add a table to a single merge field?
EDIT: I have come up with a partial solution however it is not useful for my business requirements. I am making this addition incase anyone else comes across the same issue and this works for them.
I have added a new merge field called InstalmentFile that contains the name of the XML file that will be utilized to build the table and provided that in the INCLUDETEXT, the tables underlying code now reads
{INCLUDETEXT "{MERGEFIELD InstalmentFile}" \c XML \t sample2.xsl}
This will load an external xml file and apply xsl transformations.
I have modified the database process that generates the mail merge data source to return the name of the XML file I will be generating and at the same time dump the XML that would have been in the mail merge dataset to a file in the same location as the mail merge template.
Unfortunately this won't solve my problem as its a little too messy to generate and then clean up the XML files. So if anyone has any ideas I'm still excited to hear them!