Dataset Transformed to Word via XML

  • Thread starter Thread starter jimryder
  • Start date Start date
J

jimryder

Hi,

The following snippet:

(ds is a populated dataset)

string sXSLT = @"C:\XML\template\template.xsl";
string sTemp = @"C:\XML\temp\temp.xml";
string sOutput = @"C:\XML\output\output.xml";
ds.WriteXml(sTemp);
XslTransform xslt = new XslTransform();
xslt.Load(sXSLT);
xslt.Transform(sTemp, sOutput, new XmlUrlResolver());


creates an XML word document which, when opened, loads fine - in other
words It is generating my word document OK.

However, assuming the dataset contains more than one row, then only
one word document is created, with the body of the document repeated
over and over - rather than one document per dataset row.
Is there any way to create a document per dataset row (other that
ensuring the dataset only contains one row!)??

Thanks in advance.
 
Thanks for that - where does the exsl:document bit goes exactly - here
is a snippet of my template:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core"
xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:ns0="http://tempuri.org/PrintQueueTenancyLetterForm5DS.xsd"
xmlns:st1="urn:schemas-microsoft-com:office:smarttags">
<xsl:output method="xml" encoding="UTF-8" standalone="yes" />
<xsl:template match="/">
<xsl:processing-instruction name="mso-application">
<xsl:text>progid="Word.Document"</xsl:text>
</xsl:processing-instruction>
<w:wordDocument
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core"
xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:ns0="http://tempuri.org/PrintQueueTenancyLetterForm5DS.xsd"
xmlns:st1="urn:schemas-microsoft-com:office:smarttags"
w:macrosPresent="no" w:embeddedObjPresent="yes" w:ocxPresent="no"
xml:space="preserve">
<o:SmartTagType
o:namespaceuri="urn:schemas-microsoft-com:office:smarttags"
o:name="City" />
<o:SmartTagType
o:namespaceuri="urn:schemas-microsoft-com:office:smarttags"
o:name="Street" />
<o:SmartTagType
o:namespaceuri="urn:schemas-microsoft-com:office:smarttags"
o:name="address" />
<o:SmartTagType
o:namespaceuri="urn:schemas-microsoft-com:office:smarttags"
o:name="country-region" />
<o:SmartTagType
o:namespaceuri="urn:schemas-microsoft-com:office:smarttags"
o:name="place" />
<o:DocumentProperties>
<o:Title>Form4B</o:Title>
<o:Author>Bowe</o:Author>
<o:LastAuthor>Jim Ryder</o:LastAuthor>
<o:Revision>2</o:Revision>
<o:TotalTime>1</o:TotalTime>
<o:LastPrinted>2003-02-13T16:16:00Z</o:LastPrinted>
<o:Created>2006-01-05T15:51:00Z</o:Created>
<o:LastSaved>2006-01-05T15:51:00Z</o:LastSaved>
<o:Pages>2</o:Pages>
<o:Words>340</o:Words>
<o:Characters>1944</o:Characters>
 
That's great thanks - can you/anyone help with my document - I can't work
out where to put the exsl:document tag? Ive tried a few optios:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core"
xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:ns0="http://tempuri.org/PrintQueueTenancyLetterForm5DS.xsd"
xmlns:st1="urn:schemas-microsoft-com:office:smarttags">
<xsl:output method="xml" encoding="UTF-8" standalone="yes" />
<xsl:template match="/">
<xsl:processing-instruction name="mso-application">
<xsl:text>progid="Word.Document"</xsl:text>
</xsl:processing-instruction>
<w:wordDocument
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core"
xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:ns0="http://tempuri.org/PrintQueueTenancyLetterForm5DS.xsd"
xmlns:st1="urn:schemas-microsoft-com:office:smarttags" w:macrosPresent="no"
w:embeddedObjPresent="yes" w:ocxPresent="no" xml:space="preserve">
<o:SmartTagType
o:namespaceuri="urn:schemas-microsoft-com:office:smarttags" o:name="City" />
<o:SmartTagType
o:namespaceuri="urn:schemas-microsoft-com:office:smarttags" o:name="Street"
/>
<o:SmartTagType
o:namespaceuri="urn:schemas-microsoft-com:office:smarttags" o:name="address"
/>
<o:SmartTagType
o:namespaceuri="urn:schemas-microsoft-com:office:smarttags"
o:name="country-region" />
<o:SmartTagType
o:namespaceuri="urn:schemas-microsoft-com:office:smarttags" o:name="place"
/>
<o:DocumentProperties>
<o:Title>Form4B</o:Title>
<o:Author>Bowe</o:Author>
<o:LastAuthor>Jim Ryder</o:LastAuthor>
<o:Revision>2</o:Revision>
<o:TotalTime>1</o:TotalTime>
<o:LastPrinted>2003-02-13T16:16:00Z</o:LastPrinted>
<o:Created>2006-01-05T15:51:00Z</o:Created>
<o:LastSaved>2006-01-05T15:51:00Z</o:LastSaved>
<o:Pages>2</o:Pages>
<o:Words>340</o:Words>
<o:Characters>1944</o:Characters>
<o:Company>NCHA</o:Company>
<o:Lines>16</o:Lines>
<o:Paragraphs>4</o:Paragraphs>
<o:CharactersWithSpaces>2280</o:CharactersWithSpaces>
<o:Version>8.5425</o:Version>
</o:DocumentProperties>
<w:fonts>
<w:defaultFonts w:ascii="Times New Roman" w:fareast="Times New
Roman" w:h-ansi="Times New Roman" w:cs="Times New Roman" />
</w:fonts>
<w:lists>
<w:listDef w:listDefId="0">
<w:lsid w:val="00C65B6C" />
<w:plt w:val="Multilevel" />
<w:tmpl w:val="00000000" />
<w:lvl w:ilvl="0">
<w:start w:val="1" />
<w:lvlText w:val="%1." />
<w:legacy w:legacy="on" w:legacySpace="0" w:legacyIndent="720"
/>
 
It is hard to suggest, by just looking at the XSLT.

Can you post a sample XML & call out which XML nodes, you want to go to a
seperate document?
 
Hmmmm... I think(!) I understand your question:

The template above is generated by the MS Word XML toolbar. All I then
do is apply my dataset to it. The typed dataset looks like this:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="PrintQueueTenancyLetterForm5DS"
targetNamespace="http://tempuri.org/PrintQueueTenancyLetterForm5DS.xsd"
elementFormDefault="qualified" attributeFormDefault="qualified"
xmlns="http://tempuri.org/PrintQueueTenancyLetterForm5DS.xsd"
xmlns:mstns="http://tempuri.org/PrintQueueTenancyLetterForm5DS.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="PrintQueueTenancyLetterForm5DS"
msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="PrintQueueTable">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" />
<xs:element name="Address1"
type="xs:string" />
<xs:element name="Address2"
type="xs:string" minOccurs="0" />
<xs:element name="Address3"
type="xs:string" minOccurs="0" />
<xs:element name="PostCode"
type="xs:string" minOccurs="0" />
<xs:element name="IncreaseDate"
msdata:ReadOnly="true" type="xs:dateTime" minOccurs="0" />
<xs:element name="EffectiveDate"
msdata:ReadOnly="true" type="xs:dateTime" minOccurs="0" />
<xs:element name="TenancyPK"
msdata:ReadOnly="true" msdata:AutoIncrement="true" type="xs:int" />
<xs:element name="PropertyFK" type="xs:int"
/>
<xs:element name="PeriodFK" type="xs:int"
/>
<xs:element name="Charge" type="xs:decimal"
/>
<xs:element name="Variation"
type="xs:decimal" />
<xs:element name="ApprovedBy"
type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
 
I bet this isn't the XML to which you are trying to apply the XSLT.

Snippet from your original post ...
If you post the a snippet of the XML document (temp.xml) and tell us which
nodes you want to go into each Word document, somebody on this group might
be able to help you.
 
Back
Top