Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Read XML with XSL transform into Word 2007

21 views
Skip to first unread message

Skru spammers

unread,
Nov 13, 2009, 2:53:21 PM11/13/09
to
I have a set of XML documents which I want to run through an XSL transform
and show the results, all in Word 2007.

The XML documents I get delivered and may not touch them, as they must be
passed on further.

The XSL transform I have functioning, and when I run it against any of my
source XML documents using the Java Saxon engine, it works just great, gives
me exactly the output I need. (It also uses a CSS stylesheet.)

The problem is that the result of the transform needs some slight manual
touching up. The transform creates an output file, which is nicely displayed
by either Word or a browser. When I run the transform again, while
displaying the file in a browser, a simple refresh is enough to show the new
results. But when I have the output file open in Word, the transform
crashes, since it cannot overwrite a file that Word is using.

I would like to be able to open the source XML file in Word and have the XSL
transform run against it as it opens, so that the user sees directly the
results of the transform and can further manipulate the resulting document.

I am fairly skilled in VBA and have spent quite a bit of time experimenting
with things like

Set objSchema = Application.XMLNamespaces(1)
Set objTransform = objSchema.XSLTransforms.Add("C:\Saxon\RIV2009.xsl")

and

Application.XMLNamespaces.Item(1).AttachToDocument Document:=ActiveDocument

and such, but have not managed to put together all the pieces to make this
work as I need. For instance, when I manually add the transform and try to
show the results, I get no output, despite the transform working perfectly
with Saxon. None of my coding attempts have produced anything workable and
many of them crash Word.

Is this even possible? Does the transform engine in Word work correctly? Do
I need to do something special in the transform to make it acceptable to
Word?

I can modify the transform however needed but, again, I cannot touch the
contents of the XML source files.

Pete

--

This e-mail address is fake, to keep spammers and their address harvesters
out of my hair. If you want to get in touch personally, I am 'pdanes' and I
use yahoo mail. But please use the newsgroup when possible, so that all may
benefit from the exchange of ideas.


willib

unread,
Nov 14, 2009, 6:03:37 AM11/14/09
to
Hello

just a hint..

try the Field INCLUDETEXT
it allows the insertion of an external xml-file through a transformation.
Sample:
{ INCLUDETEXT "D:\\office xml\\Winword2003 MemoSample\\Plain
MemoTest1.xml" \t "D:\\office xml\\Winword2003 MemoSample\\Memo.xsdPlain
Memo.pur.xml.XSLT" \* MERGEFORMAT }

in Word XSLTs are treated like other external code. Security must be set to
allow transformations.
The transformation result is constructed in some tmp-folder, external
references maybe not working as expected.

willib


"Skru spammers" <skrusp...@no.spam> schrieb im Newsbeitrag
news:OBFe0rJZ...@TK2MSFTNGP06.phx.gbl...

Skru spammers

unread,
Nov 15, 2009, 1:06:26 PM11/15/09
to
Thanks for the tip, I never would have thought to try an IncludeText field
for that purpose.

However, I've given it a try and even the documentation says that it should
work, but all I've gotten for output so far is "Error!" or sometimes "Error
reading file!". No explanation, no error message number. I've scanned all
sorts of NG archives and not found anything useful. Any ideas on where I
might start looking? Again, this is an XML source and XSL transform that
work perfectly under Saxon.

Pete

"willib" <wil...@NOSPAMAbreitwieser.net> p�se v diskusn�m pr�spevku
news:OZ5hpoR...@TK2MSFTNGP05.phx.gbl...

Martin Honnen

unread,
Nov 15, 2009, 1:20:26 PM11/15/09
to
Skru spammers wrote:

> However, I've given it a try and even the documentation says that it should
> work, but all I've gotten for output so far is "Error!" or sometimes "Error
> reading file!". No explanation, no error message number. I've scanned all
> sorts of NG archives and not found anything useful. Any ideas on where I
> might start looking? Again, this is an XML source and XSL transform that
> work perfectly under Saxon.

Which version of Saxon is that, which XSLT version do you use in the
stylesheet? Saxon 9 is an XSLT 2.0 processor while Microsoft does not
have any XSLT 2.0 implementation, it only supports XSLT 1.0.

--

Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/

Skru spammers

unread,
Nov 15, 2009, 1:36:44 PM11/15/09
to
Saxon version is 9.

The transform contains

<xsl:transform version="2.0"...

but I tried changing it to

<xsl:transform version="1.0"...

and no change, except Saxon warns me that I'm

"Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor"

But it still works and Word still doesn't.

Pete

Skru spammers

unread,
Nov 16, 2009, 2:57:01 AM11/16/09
to
Actually, I think you hit it. On further testing, pieces are starting to
work, when I remove version 2.0-specific functions. I'm simply going to have
to do this some other way - I need the v2 XSL stuff. Probably what I'll do
is shell a DOS process to run the Saxon engine to a temp file, then scoop up
the result with Word. I've done that sort of stuff many times in the past
and it works fine.

Thanks for the advice, I can take it from here.

Pete


"Martin Honnen" <maho...@yahoo.de> p�se v diskusn�m pr�spevku
news:OXFfSBiZ...@TK2MSFTNGP04.phx.gbl...

Martin Honnen

unread,
Nov 16, 2009, 10:36:14 AM11/16/09
to
Skru spammers wrote:
> Actually, I think you hit it. On further testing, pieces are starting to
> work, when I remove version 2.0-specific functions. I'm simply going to have
> to do this some other way - I need the v2 XSL stuff. Probably what I'll do
> is shell a DOS process to run the Saxon engine to a temp file, then scoop up
> the result with Word. I've done that sort of stuff many times in the past
> and it works fine.
>
> Thanks for the advice, I can take it from here.

As you want to use XSLT 2.0 from within Word or VBA you might also
consider AltovaXML tools instead of Saxon. It is a COM based solution
you can script with VB(A), contrary to Saxon.
See http://www.altova.com/altovaxml.html

Skru spammers

unread,
Nov 16, 2009, 12:45:42 PM11/16/09
to
That looks great, appreciate the tip. I had looked at their editor, but
found it a bit cumbersome for my limited needs and experience level. But I
thought all their stuff was for sale, I had no idea they offered this for
free. It looks like just the ticket for what I need, which is to select a
file in VBA and present the transformed result to the user. Many thanks, I'm
on it.

Pete

"Martin Honnen" <maho...@yahoo.de> p�se v diskusn�m pr�spevku

news:O3xuJKtZ...@TK2MSFTNGP05.phx.gbl...

Skru spammers

unread,
Nov 16, 2009, 1:50:05 PM11/16/09
to
Hi Martin,

Just a follow-up - that did it. The documentation takes a bit of pondering,
but it's not too bad. I finally had to go around three sides of a block: I
don't want the the resulting file opened in Word, since that precludes
overwriting it, unless the user first closes it, before running my code.
Then I tried IncludeFile, but that munches my CSS/HTML formatting. So I
create the output into a file, open the file as an invisible document, copy
the text from there, do a "PasteAndFormat wdFormatOriginalFormatting" to
preserve the look and close the invisible document, so that the file is
released for another (over)write process.

A bit clunky, but works like charm and the entire routine is less than 20
lines of VBA code.

Many thanks, you've saved me a tremendous amount of fruitless experimenting.

Pete

"Martin Honnen" <maho...@yahoo.de> p�se v diskusn�m pr�spevku

news:O3xuJKtZ...@TK2MSFTNGP05.phx.gbl...

0 new messages