This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XML to MSWord or RTF via XSL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML to MSWord or RTF via XSL" Watch "XML to MSWord or RTF via XSL" New topic
Author

XML to MSWord or RTF via XSL

CitySlicker
Greenhorn

Joined: Feb 03, 2000
Posts: 16
Has anyone out there ever taken an XML document and transformed it into MSWord format or RTF via XSL; and if so, how do you do it?
It seems XSLT is really good at transforming XML into html, txt or XML (and PDF); however, it doesn't seem all that easy for the above formats. Thanks!
Tanya Rawat
Ranch Hand

Joined: Jul 23, 2001
Posts: 31
If you got answer to this question, then please reply back, how did you do that.
Thanks
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

"CitySlicker"
your name doesn't agree with the javaranch guidelines.
please take a moment and re-register after reviewing the
guidelines at http://www.javaranch.com/name.jsp
thanks for your cooperation.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Bob DuCharme's "XSLT Quickly" has chapter 6.5 "Non-XML output" devoted to XML -> RTF conversion. Essentially, it is one small example. You can download the code from http://www.manning.com/ducharme/source.html (xq387.xsl and xq388.xml), but since I already downloaded it, I decided to post it here. Hope I wont be sued for CopyRight violation
XML:
<article>
<title author="bd" ver="1.0">My Article</title>
<p>First paragraph. 3 < 4.</p>
<p>Second paragraph. AT&T is a big company.</p>
</article>
XSL:
<!-- xq387.xsl: converts xq388.xml into xq389.rtf (sample.rtf) -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:template match="article">{\rtf1 <xsl:apply-templates/> }
</xsl:template>
<xsl:template match="title">
\par {\b <xsl:apply-templates/>}
</xsl:template>
<xsl:template match="p">
\par <xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>

For automatic conversion, XML software recommends two programs:
XTAL's http://www.zeigermann.de/xtal.html
rdc2rtf http://www.sema.be/mtc/products/rdc2rtf/index.html
- I did not try them myself, though.

[This message has been edited by Mapraputa Is (edited August 13, 2001).]


Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
a glover
Greenhorn

Joined: Aug 14, 2001
Posts: 12
Thank you very much, the example you posted is most informative. Now, it seems it is just a matter of mastering RTF. For those interested in RTF, there is a link:
http://msdn.microsoft.com/library/?url=/library/en-us/dnrtfspec/html/rtfspec.asp?frame=true
Alas, the CitySlicker alias has been retired in favor of my new one. Thanks for pointing out my error!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML to MSWord or RTF via XSL