Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xslt word 2003

Status
Not open for further replies.

bont

Programmer
Sep 7, 2000
200
US
I have an XSLT set up to generate a word 2003 document. It works, but it defaults to utf-16. Have tried to change encoding to utf-8, but it doesn't change. Is this something I must change in my VB code during the transform, or is this just a bug of the vb.net? Am I missing something?
 
Code:
<xsl:output encoding="utf-8"/>
This didn't work?
 
No, just changing the encoding value does not work, it stays with utf-16. I am using VB.net 2002 to perform the transform to create XML for Word 2003.

VB.net code
Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Prepare StringWriter for results
        Dim sw As System.IO.StringWriter = New System.IO.StringWriter()
        'Load xml file into XMLDoc
        Dim XMLDoc As XPathDocument = New XPathDocument("C:\Redix\HGApps\WindowsApplication3\WindowsApplication3\XMLFile1.xml")
        'Load XSL
        Dim XSLTDoc As XslTransform = New XslTransform()
        XSLTDoc.Load("C:\Redix\HGApps\WindowsApplication3\WindowsApplication3\XSLTFile1.xsl")
        'Transform XMLDoc and dump HTML results to stringwriter -> sw
        XSLTDoc.Transform(XMLDoc, Nothing, sw)
        'Pull results out of stringwriter and populate literal
        TextBox1.Text = sw.ToString()
    End Sub

XSLT code
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] xmlns:w="[URL unfurl="true"]http://schemas.microsoft.com/office/word/2003/wordml"[/URL] >
<xsl:output method="xml"  indent="yes" omit-xml-declaration="yes" />
<xsl:template match="/">
	<xsl:processing-instruction name="mso-application">
		<xsl:text>progid="Word.Document"</xsl:text>
	</xsl:processing-instruction>
	<w:wordDocument>
		<w:body>
			<xsl:apply-templates select="Courses/Course" />
		</w:body>
	</w:wordDocument>
	</xsl:template>
	<xsl:template match="Course">
		<w:p>
			<w:r>
				<w:t>
					<xsl:value-of select="@Number" />, <xsl:value-of select="Title"/>
				</w:t>
			</w:r>
		</w:p>
	</xsl:template>
</xsl:stylesheet>
 
This is a suggestion to dig deeper into the Word API: Word produces Unicode (UTF-16) output by default, no? That suggests that you'd have to do something affirmative to produce UTF-8; just calling it UTF-8 wouldn't be sufficient.
 
I have looked at many examples, which all say to use utf-8. My app will only produce utf-16. I have told it to not print the <? xml ?> tag at all and word assumes utf-8, so it works fine now, but I still would like to know what causes it to default to utf-16?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top