The XML has repetitive node OptionCd
<AdjusterParty AdjusterPartyIdRef="20130000074-001">
<Option>
<OptionCd>SAL</OptionCd>
<OptionValue>N</OptionValue>
</Option>
<Option>
<OptionCd>SUB</OptionCd>
<OptionValue>N</OptionValue>
</Option>
</AdjusterParty>
The xslt is:
<w:p >
<w:r>
<w:t>
<xsl:value-of select ="OptionCd"/>
</w:r>
</w:p>
The requirement is based on the parameter value passed in the function I would either populate the OptionCD SAL or SUB. So how to set the value in OptionCD.
The C# code is
function node(int count)
{
}
is there something like based on the count, I can tell the xslt to fetch that node, say count is
1, then could I let the xslt know it need to print the first OptionCd and so on.
Thanks
Updated the code which I use to read the xml and xslt from a template document and then generates the word document with the values.
string rootPath = @"C:\ExampleWordProcessingML\Docs";
string xmlDataFile = rootPath + @"\Original.xml";
string xsltFile = rootPath + @"\Transactions.xslt";
string templateDocument = rootPath + @"\Transactions.docx";
string outputDocument = rootPath + @"\MyTransactions.docx";
//Create a writer for the output of the Xsl Transformation.
StringWriter stringWriter = new StringWriter();
XmlWriter xmlWriter = XmlWriter.Create(stringWriter);
//Create the Xsl Transformation object.
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(xsltFile);
//Transform the xml data into Open XML 2.0 Wordprocessing format.
transform.Transform(xmlDataFile, xmlWriter);
//Create an Xml Document of the new content.
XmlDocument newWordContent = new XmlDocument();
newWordContent.LoadXml(stringWriter.ToString());
//Copy the Word 2007 source document to the output file.
System.IO.File.Copy(templateDocument, outputDocument, true);
//Use the Open XML SDK version 2.0 to open the output
// document in edit mode.
using (WordprocessingDocument output =
WordprocessingDocument.Open(outputDocument, true))
{
//Using the body element within the new content XmlDocument
// create a new Open Xml Body object.
Body updatedBodyContent =
new Body(newWordContent.DocumentElement.InnerXml);
//Replace the existing Document Body with the new content.
output.MainDocumentPart.Document.Body = updatedBodyContent;
//Save the updated output document.
output.MainDocumentPart.Document.Save();
}