Listing 1: XSD defining an employee structure

<?xml version="1.0"?>
<schema targetNamespace="http://localhost/timesheet/info" 
	xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:employee="http://localhost/timesheet/info" 
		elementFormDefault="qualified">

<element name="prefix" type="string"/>
<element name="firstname" type="string"/>
<element name="lastname" type="string"/>
<element name="suffix" type="string"/>
<element name="email" type="string"/>
<element name="employeeid" type="string"/>
<element name="costcenter" type="string"/>

<element name="employeeinfo">
<complexType>
	<sequence>
		<element ref="employee:prefix"  minOccurs="0"/>
		<element ref="employee:firstname"/>
		<element ref="employee:lastname"/>
		<element ref="employee:suffix" minOccurs="0"/>
		<element ref="employee:email"/>
		<element ref="employee:employeeid"/>
		<element ref="employee:costcenter"/>
	</sequence>
</complexType>
</element>
</schema>

Listing 2: The XML document created for the employee schema

<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.1"
 productVersion="11.0.6357" PIVersion="1.0.0.0"
 href="file:///C:\Documents%20and%20Settings\trobbins.NORTHAMERICA\My%20Documents\Writings\
  Office%20XML%20Article\Template2.xsn"
   name="urn:schemas-microsoft-com:office:infopath:Template2:http---localhost-timesheet-info"
    language="en-us" ?><?mso-application progid="InfoPath.Document"?><employee:employeeinfo
	 xmlns:employee="http://localhost/timesheet/info">
	<employee:prefix>Mr.</employee:prefix>
	<employee:firstname>Thomas</employee:firstname>
	<employee:lastname>Robbins</employee:lastname>
	<employee:suffix></employee:suffix>
	<employee:email>trobbins@microsoft.com</employee:email>
	<employee:employeeid>12345</employee:employeeid>
	<employee:costcenter>12567</employee:costcenter>
</employee:employeeinfo>

Listing 3: Sample code to instantiate a transformation within VB.NET

Private Sub ConvertToWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
 ConvertToWord.Click
Dim filename As String
With OpenInfoPath
.Filter = "InfoPath files(o.xml)|o.xml"
.ShowDialog()
filename = .FileName
End With

If filename <> "" Then
Dim stylefile As String
Dim xslt As New System.Xml.Xsl.XslTransform
With OpenInfoPath
.Filter = "XSLT files(o.xslt)|o.xslt"
.ShowDialog()
stylefile = .FileName
End With

If stylefile <> "" Then
xslt.Load(stylefile)
xslt.Transform(filename, "out.xml", Nothing)
Else
MsgBox("Please select a style sheet file!")
End If
Else
MsgBox("Please select an InfoPath file")
End If
End Sub

Listing 4: The XSLT transformation used to convert an InfoPath document to a Word document

<xsl:stylesheet version="1.0"
 xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-03-28T01:27:16"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:o="urn:schemas-microsoft-com:office:office"
  xmlns:w="http://schemas.microsoft.com/office/word/2003/2/wordml">

<xsl:template match="my:myFields">
<xsl:processing-instruction name="mso-application">progid="Word.Document"</xsl:processing-instruction>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/2/wordml">

	<o:DocumentProperties>
		<o:Title>My Company Name List</o:Title>
    </o:DocumentProperties>

	<w:body>
		<xsl:for-each select="my:NameList">
			<w:p>
				<w:r>
					<w:t>Customer Name</w:t>
					<w:t><xsl:value-of select="my:FirstName"/></w:t>
					<w:t><xsl:value-of select="my:LastName"/></w:t>
				</w:r>
			</w:p>
		</xsl:for-each>
	</w:body>
</w:wordDocument>

</xsl:template>
</xsl:stylesheet> >