Solved

Using Word to create XSLT

Posted on 2007-04-11
10
2,589 Views
Last Modified: 2012-05-05
I want to know if there is a way to create the xslt file needed to transform my XML data into a Word document using Word itself....and how to do it.
I control the data.  My clients will want the ability to create their own merge letters and documents.  Because of the flat nature of Word Mail Merge, it appears that I will need to either use Automation, or XSLT.  I would rather use the latter if possible.
I can provide the schema for Word, and the user can create their document dropping in the tags.  I can have them save it as XML.  Is there a way that I can take that saved Word XML document and turn it into xslt.  Not a problem if it has to be done programmatically, I can write that, but I don't want the users to have to go through and create their own xslt.  Or is there a way to save a Word document or template as xslt then use it on my xml data.
And to add to the mix, this has to work in 2003 or 2007.
0
Comment
Question by:dugjohnson
  • 5
  • 4
10 Comments
 
LVL 7

Expert Comment

by:gbahri
ID: 18889746
0
 
LVL 1

Author Comment

by:dugjohnson
ID: 18890085
Those links describe how to create Word documents using XSLT and XML.  That is where I am heading.  I want to use Word to create the XSLT file....actually for my clients to use Word to create the XSLT files, which I will then combine with XML extracts to create Word documents for printing.
Again, the problem is creating XSLT from Word so that it has the needed formatting, NOT creating the XSLT file by hand to generate a Word document.
0
 
LVL 13

Expert Comment

by:R7AF
ID: 18892148
I imagine that you want the following. You have an xml-datasource, and then want to let a client create a Word document, and drag xml-fields into the Word document, similar to e.g. Dreamweaver with a datasource. The result is an xslt document, which can be applied to the xml data to create a Word document.

I don't know if this can be done in Word. You can try Infopath and/or Sharepoint Server. I believe those are made for stuff like this. Start with Infopath, and see how it works out for you.

Try the following links. This is probably not exactly what you are looking for, but it's a start.
http://office.microsoft.com/en-us/infopath/HA101514381033.aspx#4
http://msdn2.microsoft.com/en-us/library/aa662316(office.11).aspx
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Author Comment

by:dugjohnson
ID: 18892791
If it was just me and not 3000 clients I would do that, but I am not able to require InfoPath.  It does look interesting though.
0
 
LVL 13

Expert Comment

by:R7AF
ID: 18893600
Try this:

1) Let the customer create an example Word document like they want it to be.
2) Provide them with names for all the data fields they can use, e.g. firstName, lastName, etc.
3) These data field names should be enclosed in % or # characters, which makes them easily replaceble.  
4) The customers should insert those fields (like %firstName%) into the document instead of the example firstname.
5) Let them save it as XML
6) Then they can upload it to your webserver
7) You parse the documents and create the XSLT by extracting the data field names from the word-xml file.
0
 
LVL 1

Author Comment

by:dugjohnson
ID: 18893704
I can even go a step further by having them attach the schema for my tables to Microsoft Word and just drop the XML tags into place.  The crux of the problem is your #7.
I want to know how to either
A) Have Word take that saved XML version and change it to an XSLT or
B) What do I need to do to turn that XML into an XSLT?   The XML has a LOT of stuff that doesn't look like an XSLT.  What is the process of turning a Word XML file into an XSLT?
0
 
LVL 13

Expert Comment

by:R7AF
ID: 18893873
I suppose you use a webserver where the documents are uploaded. You can then use ASP/JSP/PHP - whatever - to replace the %firstName% and create proper <xsl:value-of> tags. I doubt if you can do this with XSLT alone.

Still, if you need to repeat rows of data, like in a table, it gets more complicated. I don't know if you need that?

(A) is not an option AFAIK.
0
 
LVL 1

Author Comment

by:dugjohnson
ID: 18893903
As an aside, does anyone know if InfoPath comes with all versions of Microsoft Office as of 2003?  If it does that could solve the problem, but if my clients have to pay extra for it, then it is not a solution for me, unfortunately.
0
 
LVL 13

Accepted Solution

by:
R7AF earned 500 total points
ID: 18900497
0
 
LVL 1

Author Comment

by:dugjohnson
ID: 18900970
OK, I've solved my own problem, at least as much as is possible.
There isn't a good way to create XSLT from Word directly.  Microsoft does have an XSLT Inference tool
http://msdn2.microsoft.com/en-us/library/aa212886(office.11).aspx
that works with Word 2003 XML documents (even those saved as Word 2003 XML from Word 2007) but the XSLT is not quite as satisfying as I would like yet.
I will be posting some conversion code myself a little later once I get it all figured out, but I am awarding the points to R7AF just because they hung in, and did, actually, answer my sub-question.
Thanks
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question