How to apply WordML.xslt to DataOnly.xml programmatically?

Hello,

I have a typical requirement for which I could not find any related examples on internet.

I would like to programmatically(.NET or VSTO with C#) load xml data and apply XSLT to

create a word 2003 document.

Here what I do:

  1. User provides me a formatted word template (Original.doc with placeholders which my application should fill in and save as separate document).
  2. I attach MyXsd.xsd document to it and bind the elements to the place(placeholders) where data should be displayed.
  3. I save the document as xxxWordML.xml with both data and format.
  4. I save the document as DataOnly.xml.
  5. With WML2XSLT.exe, I generate xxxWordML.xslt from xxxWordML.xml.

Now I can manually open the DataOnly.xml in Word 2003 and attach xxxWordML.xslt (in XML data view) which will bring me back the same view as Original.doc. Here I can edit the DataOnly.xml which confirms to MyXsd.xsd and will be reflected when I open it in Word as the way just said.

Limitation:

I should use the xslt template generated by WML2XSLT.exe as user will change the static text and format the document now and then without disturbing the xsd placeholders.

I want to know how I can write a program which will load DataOnly.xml and apply the xxxWordML.xslt and save it as a final report document (which should look like Original.doc but with different values in placeholders as per DataOnly.xml)

Is it possible in .NET or VSTO 2005 with C# if yes, could you please provide me some sample code or links to the resources.

Thanks in advance,

Kris



Answer this question

How to apply WordML.xslt to DataOnly.xml programmatically?

  • Barb O

    Is it possible to do the 3rd and 5th steps mentioned above programmatically.

    1. I mean saving the word doc as xml type without opening Word Application.

    3. Then instead of using wml2xslt.exe, generate XSLT file from the xml file programmatically.

    TIA,

    Kris


  • EricN

    Hi Kris,

    May be this is what you are looking for..

    String xsltFile = "C:\\VSTOProjects\\YourWordML.xslt";

    String xmlFile = "C:\\VSTOProjects\\Your_DataOnly.xml";

    //String finalDocument = "C:\\VSTOProjects\\YourFinalWord.doc";

    String finalDocument = "C:\\VSTOProjects\\YourFinalWord.xml";

    XslCompiledTransform myXslTransform = new XslCompiledTransform();

    myXslTransform.Load(xsltFile);

    myXslTransform.Transform(xmlFile, finalDocument);

    Srinivas Gonukula


  • sirck sirck

    Thank you

    It works.

    Kris


  • Keith Henkel

    the Word 2003 object model has the TransformDocument method of the Document object. Does that not do what you require

  • How to apply WordML.xslt to DataOnly.xml programmatically?