I don't know why it's not working in my case.
I attach my VB.NET method and also my XSLT source.
the target fieldname is "Description" in "Parent" table.
Private Sub CreateWordDoc()
Dim ds As New dsTest
Dim drParent As dsTest.ParentsRow = ds.Parents.NewParentsRow
drParent.ParentId = "1"
drParent.FirstName = "PF1"
drParent.LastName = "PL1"
drParent.Description = "Tjen1" + vbCrLf + "Barsh1"
drParent.Table.Rows.Add(drParent)
drParent = ds.Parents.NewParentsRow
drParent.ParentId = "2"
drParent.FirstName = "PF2"
drParent.LastName = "PL2"
drParent.Description = "Tjen2 " + vbCrLf + " Barsh2"
drParent.Table.Rows.Add(drParent)
Dim drChild As dsTest.ChildsRow = ds.Childs.NewChildsRow
drChild.ParentId = "1"
drChild.FirstName = "FCF1-1"
drChild.LastName = "FCL1-1"
drChild.Table.Rows.Add(drChild)
drChild = ds.Childs.NewChildsRow
drChild.ParentId = "1"
drChild.FirstName = "FCF1-2"
drChild.LastName = "FCL1-2"
drChild.Table.Rows.Add(drChild)
drChild = ds.Childs.NewChildsRow
drChild.ParentId = "2"
drChild.FirstName = "FCF2-1"
drChild.LastName = "FCL2-1"
drChild.Table.Rows.Add(drChild)
drChild = ds.Childs.NewChildsRow
drChild.ParentId = "2"
drChild.FirstName = "FCF2-2"
drChild.LastName = "FCL2-2"
drChild.Table.Rows.Add(drChild)
drChild = ds.Childs.NewChildsRow
drChild.ParentId = "2"
drChild.FirstName = "FCF2-3"
drChild.LastName = "FCL2-3"
drChild.Table.Rows.Add(drChild)
Dim xslt As XslCompiledTransform = New XslCompiledTransform(True)
IO.File.Delete("d:\test.xml")
IO.File.Delete("d:\test.doc")
Dim xws As New Xml.XmlWriterSettings()
Dim xrs As New Xml.XmlReaderSettings()
Dim xmlW As Xml.XmlWriter = Xml.XmlWriter.Create("d:\test.xml", xws)
Dim xmlR As Xml.XmlReader = Xml.XmlReader.Create("d:\test2.xsl", xrs)
ds.WriteXml(xmlW)
xmlW.Close()
xslt.Load(xmlR)
xslt.Transform("d:\test.xml", "d:\test.doc")
xslt = Nothing
Process.Start("d:\test.doc")
End Sub
-----------------------------------------------------------------------------
XSL file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" xmlns:ns0="http://tempuri.org/dsTest.xsd">
<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:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" xmlns:ns0="http://tempuri.org/dsTest.xsd" w:macrosPresent="no" w:embeddedObjPresent="no" w:ocxPresent="no" xml:space="preserve">
<w:ignoreSubtree w:val="http://schemas.microsoft.com/office/word/2003/wordml/sp2" />
<o:DocumentProperties>
<o:Author>bsotoudeh</o:Author>
<o:LastAuthor>bsotoudeh</o:LastAuthor>
<o:Revision>4</o:Revision>
<o:TotalTime>1</o:TotalTime>
<o:Created>2009-10-22T08:28:00Z</o:Created>
<o:LastSaved>2009-10-22T08:31:00Z</o:LastSaved>
<o:Pages>1</o:Pages>
<o:Words>16</o:Words>
<o:Characters>97</o:Characters>
<o:Company>Organization</o:Company>
<o:Lines>1</o:Lines>
<o:Paragraphs>1</o:Paragraphs>
<o:CharactersWithSpaces>112</o:CharactersWithSpaces>
<o:Version>12</o:Version>
</o:DocumentProperties>
<w:fonts>
<w:defaultFonts w:ascii="Calibri" w:fareast="Calibri" w:h-ansi="Calibri" w:cs="Arial" />
<w:font w:name="Arial">
<w:panose-1 w:val="020B0604020202020204" />
<w:charset w:val="00" />
<w:family w:val="Swiss" />
<w:pitch w:val="variable" />
<w:sig w:usb-0="20002A87" w:usb-1="80000000" w:usb-2="00000008" w:usb-3="00000000" w:csb-0="000001FF" w:csb-1="00000000" />
</w:font>
<w:font w:name="Cambria Math">
<w:panose-1 w:val="02040503050406030204" />
<w:charset w:val="01" />
<w:family w:val="Roman" />
<w:notTrueType />
<w:pitch w:val="variable" />
<w:sig w:usb-0="00000000" w:usb-1="00000000" w:usb-2="00000000" w:usb-3="00000000" w:csb-0="00000000" w:csb-1="00000000" />
</w:font>
<w:font w:name="Calibri">
<w:panose-1 w:val="020F0502020204030204" />
<w:charset w:val="00" />
<w:family w:val="Swiss" />
<w:pitch w:val="variable" />
<w:sig w:usb-0="A00002EF" w:usb-1="4000207B" w:usb-2="00000000" w:usb-3="00000000" w:csb-0="0000009F" w:csb-1="00000000" />
</w:font>
</w:fonts>
<w:styles>
<w:versionOfBuiltInStylenames w:val="7" />
<w:latentStyles w:defLockedState="off" w:latentStyleCount="267">
<w:lsdException w:name="Normal" />
<w:lsdException w:name="heading 1" />
<w:lsdException w:name="heading 2" />
<w:lsdException w:name="heading 3" />
<w:lsdException w:name="heading 4" />
<w:lsdException w:name="heading 5" />
<w:lsdException w:name="heading 6" />
<w:lsdException w:name="heading 7" />
<w:lsdException w:name="heading 8" />
<w:lsdException w:name="heading 9" />
<w:lsdException w:name="caption" />
<w:lsdException w:name="Title" />
<w:lsdException w:name="Subtitle" />
<w:lsdException w:name="Strong" />
<w:lsdException w:name="Emphasis" />
<w:lsdException w:name="No Spacing" />
<w:lsdException w:name="List Paragraph" />
<w:lsdException w:name="Quote" />
<w:lsdException w:name="Intense Quote" />
<w:lsdException w:name="Subtle Emphasis" />
<w:lsdException w:name="Intense Emphasis" />
<w:lsdException w:name="Subtle Reference" />
<w:lsdException w:name="Intense Reference" />
<w:lsdException w:name="Book Title" />
<w:lsdException w:name="TOC Heading" />
</w:latentStyles>
<w:style w:type="paragraph" w:default="on" w:styleId="Normal">
<w:name w:val="Normal" />
<w:rsid w:val="00F401BB" />
<w:pPr>
<w:spacing w:after="200" w:line="276" w:line-rule="auto" />
</w:pPr>
<w:rPr>
<wx:font wx:val="Calibri" />
<w:sz w:val="22" />
<w:sz-cs w:val="22" />
<w:lang w:val="EN-AU" w:fareast="EN-US" w:bidi="AR-SA" />
</w:rPr>
</w:style>
<w:style w:type="character" w:default="on" w:styleId="DefaultParagraphFont">
<w:name w:val="Default Paragraph Font" />
</w:style>
<w:style w:type="table" w:default="on" w:styleId="TableNormal">
<w:name w:val="Normal Table" />
<wx:uiName wx:val="Table Normal" />
<w:rPr>
<wx:font wx:val="Calibri" />
<w:lang w:val="EN-AU" w:fareast="EN-AU" w:bidi="AR-SA" />
</w:rPr>
<w:tblPr>
<w:tblInd w:w="0" w:type="dxa" />
<w:tblCellMar>
<w:top w:w="0" w:type="dxa" />
<w:left w:w="108" w:type="dxa" />
<w:bottom w:w="0" w:type="dxa" />
<w:right w:w="108" w:type="dxa" />
</w:tblCellMar>
</w:tblPr>
</w:style>
<w:style w:type="list" w:default="on" w:styleId="NoList">
<w:name w:val="No List" />
</w:style>
</w:styles>
<w:shapeDefaults>
<o:shapedefaults v:ext="edit" spidmax="11266" />
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout>
</w:shapeDefaults>
<w:docPr>
<w:view w:val="print" />
<w:zoom w:percent="100" />
<w:doNotEmbedSystemFonts />
<w:proofState w:spelling="clean" w:grammar="clean" />
<w:defaultTabStop w:val="720" />
<w:punctuationKerning />
<w:characterSpacingControl w:val="DontCompress" />
<w:optimizeForBrowser />
<w:relyOnVML />
<w:allowPNG />
<w:validateAgainstSchema />
<w:saveInvalidXML />
<w:ignoreMixedContent />
<w:alwaysShowPlaceholderText w:val="off" />
<w:compat>
<w:breakWrappedTables />
<w:snapToGridInCell />
<w:wrapTextWithPunct />
<w:useAsianBreakRules />
<w:dontGrowAutofit />
</w:compat>
<wsp:rsids>
<wsp:rsidRoot wsp:val="00C10940" />
<wsp:rsid wsp:val="001B0C8A" />
<wsp:rsid wsp:val="0034667E" />
<wsp:rsid wsp:val="003F3B70" />
<wsp:rsid wsp:val="00400629" />
<wsp:rsid wsp:val="004B2F6E" />
<wsp:rsid wsp:val="00560B9C" />
<wsp:rsid wsp:val="006B4C02" />
<wsp:rsid wsp:val="0073349E" />
<wsp:rsid wsp:val="00814146" />
<wsp:rsid wsp:val="00952D81" />
<wsp:rsid wsp:val="009C2E96" />
<wsp:rsid wsp:val="00A60BBC" />
<wsp:rsid wsp:val="00A73B15" />
<wsp:rsid wsp:val="00A93CC1" />
<wsp:rsid wsp:val="00AA5CC1" />
<wsp:rsid wsp:val="00B728DD" />
<wsp:rsid wsp:val="00C10940" />
<wsp:rsid wsp:val="00D14522" />
<wsp:rsid wsp:val="00EB66ED" />
<wsp:rsid wsp:val="00F401BB" />
</wsp:rsids>
<w:showXMLTags w:val="off" />
</w:docPr>
<w:body>
<xsl:apply-templates select="ns0:dsTest" />
<w:sectPr wsp:rsidR="00F401BB" wsp:rsidRPr="006B4C02" wsp:rsidSect="00F401BB">
<w:pgSz w:w="11906" w:h="16838" />
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0" />
<w:cols w:space="708" />
<w:docGrid w:line-pitch="360" />
</w:sectPr>
</w:body>
<o:CustomDocumentProperties>
<o:processingInstructions dt:dt="string"> <xsl:for-each select="processing-instruction()"><xsl:text><?</xsl:text><xsl:value-of select="name()" /><xsl:text> </xsl:text><xsl:value-of select="." /><xsl:text>?></xsl:text></xsl:for-each></o:processingInstructions>
</o:CustomDocumentProperties>
</w:wordDocument>
</xsl:template>
<xsl:template match="/ns0:dsTest">
<ns0:dsTest>
<xsl:for-each select="@ns0:*|@*[namespace-uri()='']">
<xsl:attribute name="{name()}" namespace="{namespace-uri()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<w:p wsp:rsidR="006B4C02" wsp:rsidRDefault="006B4C02" wsp:rsidP="006B4C02" />
<w:p wsp:rsidR="006B4C02" wsp:rsidRDefault="006B4C02" wsp:rsidP="006B4C02" />
<xsl:apply-templates select="ns0:Parents" />
<w:p wsp:rsidR="006B4C02" wsp:rsidRDefault="006B4C02" wsp:rsidP="006B4C02" />
<w:p wsp:rsidR="00F401BB" wsp:rsidRPr="006B4C02" wsp:rsidRDefault="00814146" wsp:rsidP="006B4C02" />
</ns0:dsTest>
</xsl:template>
<xsl:template match="/ns0:dsTest/ns0:Parents">
<ns0:Parents>
<xsl:for-each select="@ns0:*|@*[namespace-uri()='']">
<xsl:attribute name="{name()}" namespace="{namespace-uri()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<w:p wsp:rsidR="006B4C02" wsp:rsidRDefault="006B4C02" wsp:rsidP="006B4C02" />
<w:p wsp:rsidR="006B4C02" wsp:rsidRDefault="0073349E" wsp:rsidP="006B4C02">
<w:r>
<w:t>
<xsl:text>ParentID</xsl:text>
</w:t>
</w:r>
<w:r>
<w:t>
<xsl:text>=</xsl:text>
</w:t>
</w:r>
<xsl:apply-templates select="ns0:ParentId" />
</w:p>
<w:p wsp:rsidR="006B4C02" wsp:rsidRDefault="0073349E" wsp:rsidP="006B4C02">
<w:r>
<w:t>
<xsl:text>FirstName</xsl:text>
</w:t>
</w:r>
<w:r>
<w:t>
<xsl:text>=</xsl:text>
</w:t>
</w:r>
<xsl:apply-templates select="ns0:FirstName" />
</w:p>
<w:p wsp:rsidR="006B4C02" wsp:rsidRDefault="0073349E" wsp:rsidP="006B4C02">
<w:r>
<w:t>
<xsl:text>LastName</xsl:text>
</w:t>
</w:r>
<w:r>
<w:t>
<xsl:text>=</xsl:text>
</w:t>
</w:r>
<xsl:apply-templates select="ns0:LastName" />
</w:p>
<w:p wsp:rsidR="006B4C02" wsp:rsidRDefault="0073349E" wsp:rsidP="006B4C02">
<w:r>
<w:t>
<xsl:text>Description=</xsl:text>
</w:t>
</w:r>
<xsl:apply-templates select="ns0:Description" />
</w:p>
<w:p wsp:rsidR="0073349E" wsp:rsidRDefault="0073349E" wsp:rsidP="006B4C02">
<w:r>
<w:t>
<xsl:text>-Childs</xsl:text>
</w:t>
</w:r>
</w:p>
<xsl:apply-templates select="ns0:Childs" />
<w:p wsp:rsidR="0073349E" wsp:rsidRDefault="0073349E" wsp:rsidP="0073349E">
<w:r>
<w:t>
<xsl:text>-</xsl:text>
</w:t>
</w:r>
<w:r>
<w:t>
<xsl:text>Childs(</xsl:text>
</w:t>
</w:r>
<w:r>
<w:t>
<xsl:text>End(</xsl:text>
</w:t>
</w:r>
</w:p>
<w:p wsp:rsidR="0073349E" wsp:rsidRDefault="0073349E" wsp:rsidP="006B4C02" />
<w:p wsp:rsidR="006B4C02" wsp:rsidRDefault="00814146" wsp:rsidP="006B4C02" />
</ns0:Parents>
</xsl:template>
<xsl:template match="/ns0:dsTest/ns0:Parents/ns0:Description">
<ns0:Description>
<xsl:attribute xml:space ="preserve" name="Description"></xsl:attribute>
<w:r>
<w:t>
<xsl:value-of select="."/>
<xsl:text></xsl:text>
</w:t>
</w:r>
</ns0:Description>
</xsl:template>
<xsl:template match="/ns0:dsTest/ns0:Parents/ns0:Childs">
<ns0:Childs>
<xsl:for-each select="@ns0:*|@*[namespace-uri()='']">
<xsl:attribute name="{name()}" namespace="{namespace-uri()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<w:p wsp:rsidR="00D14522" wsp:rsidRDefault="00D14522" wsp:rsidP="006B4C02" />
<w:p wsp:rsidR="00D14522" wsp:rsidRDefault="0073349E" wsp:rsidP="006B4C02">
<w:r>
<w:t>
<xsl:text>FirstName</xsl:text>
</w:t>
</w:r>
<w:r>
<w:t>
<xsl:text>=</xsl:text>
</w:t>
</w:r>
<xsl:apply-templates select="ns0:FirstName" />
</w:p>
<w:p wsp:rsidR="00D14522" wsp:rsidRDefault="0073349E" wsp:rsidP="006B4C02">
<w:r>
<w:t>
<xsl:text>LastName</xsl:text>
</w:t>
</w:r>
<w:r>
<w:t>
<xsl:text>=</xsl:text>
</w:t>
</w:r>
<xsl:apply-templates select="ns0:LastName" />
</w:p>
<w:p wsp:rsidR="006B4C02" wsp:rsidRDefault="00814146" wsp:rsidP="006B4C02" />
</ns0:Childs>
</xsl:template>
<xsl:template match="/ns0:dsTest/ns0:Parents/ns0:ParentId">
<ns0:ParentId>
<xsl:for-each select="@ns0:*|@*[namespace-uri()='']">
<xsl:attribute name="{name()}" namespace="{namespace-uri()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<w:r>
<w:t>
<xsl:value-of select="." />
</w:t>
</w:r>
</ns0:ParentId>
</xsl:template>
<xsl:template match="/ns0:dsTest/ns0:Parents/ns0:FirstName|/ns0:dsTest/ns0:Parents/ns0:Childs/ns0:FirstName">
<ns0:FirstName>
<xsl:for-each select="@ns0:*|@*[namespace-uri()='']">
<xsl:attribute name="{name()}" namespace="{namespace-uri()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<w:r>
<w:t>
<xsl:value-of select="." />
</w:t>
</w:r>
</ns0:FirstName>
</xsl:template>
<xsl:template match="/ns0:dsTest/ns0:Parents/ns0:Childs/ns0:LastName|/ns0:dsTest/ns0:Parents/ns0:LastName">
<ns0:LastName>
<xsl:for-each select="@ns0:*|@*[namespace-uri()='']">
<xsl:attribute name="{name()}" namespace="{namespace-uri()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<w:r>
<w:t>
<xsl:value-of select="." />
</w:t>
</w:r>
</ns0:LastName>
</xsl:template>
</xsl:stylesheet>
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456:





by: kmartin7Posted on 2009-10-22 at 05:41:56ID: 25633393
This can be tricky depending on a number of variables. I just use <xsl:text> with a hard-typed return when I have problems, such as:
<xsl:template match="myElement">
<xsl:value-of select="."/><xsl:text>
</xsl:text>
</xsl:template>
This will maintain spacing and carriage returns. It isn't always the most elegant solution, but it works.