Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8392421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:30:58+00:00 2026-06-09T19:30:58+00:00

I have an XML file whose contents I need to import into a Microsoft

  • 0

I have an XML file whose contents I need to import into a Microsoft Word 2007 document.

I have an XSL file that constructs a WordprocessingML table:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
<xsl:output method="xml" indent="yes"/> 

<w:style w:type="table" w:styleId="TableStyle">
    <w:name w:val="Table Style"/>
    <w:tblPr>
        <w:tblBorders>
            <w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/>
        </w:tblBorders>
    </w:tblPr>
</w:style>  

<xsl:template match="list">

    <xsl:processing-instruction name="mso-application">
        <xsl:text>progid="Word.Document"</xsl:text>
    </xsl:processing-instruction>

    <w:tbl>
        <w:tblPr>
            <w:tblStyle w:val="TableStyle"/>
        </w:tblPr>
        <w:tblGrid>
            <w:gridCol w:w="100" />
            <w:gridCol w:w="200" />
            <w:gridCol w:w="1024" />
        </w:tblGrid>
        <w:tr>
            <w:tc><w:p><w:r><w:t>ID</w:t></w:r></w:p></w:tc>
            <w:tc><w:p><w:r><w:t>Description</w:t></w:r></w:p></w:tc>   
        </w:tr> 
        <xsl:apply-templates select="items/item">
            <xsl:sort select="id" order="ascending"/>
        </xsl:apply-templates>
    </w:tbl>

</xsl:template>

<xsl:template match="items/item">
    <w:tr>
        <w:tc><w:p><w:r><w:t>
            <xsl:value-of select="id"/>
        </w:t></w:r></w:p></w:tc>
        <w:tc><w:p><w:r><w:t>
            <xsl:value-of select="description"/>
        </w:t></w:r></w:p></w:tc>
    </w:tr>
</xsl:template>
</xsl:stylesheet>

I use the Word INCLUDETEXT field to import the XML file and apply the transformation:

{INCLUDETEXT  "E:\\Spinner\\Documents\\data.xml" \t "E:\\Spinner\\Documents\\stylesheet.xsl"}

This works fine as far as actually importing the data is concerned – a basic table is displayed with the data I need.

The table, however, is devoid of any formatting – no borders, no gridlines, no shading, etc. Word ignores the column widths I specified in my XSL file (<w:gridCol w:w="100" />, etc.) and sets its own.

I need to format it using (preferably) a style already present in the document, such as “Table Grid”, or “Medium Shading 1 – Accent 3.” However, I can’t get Word to actually apply the style, either for an already-present-in-Word-document style (<w:tblStyle w:val="TableGrid"/>), or a newly-defined-in-XSL-file style (<w:tblStyle w:val="TableStyle"/>).

Has anyone any pointers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:31:00+00:00Added an answer on June 9, 2026 at 7:31 pm

    You need something more like this, but I think you may need to adjust the column widths (possibly to take account of the cell borders)

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
    <xsl:output method="xml" indent="yes"/> 
    
    <xsl:template match="list">
      <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"  w:macrosPresent="no" w:embeddedObjPresent="no" 
    w:ocxPresent="no" xml:space="preserve">
        <w:styles>
          <w:style w:type="table" w:styleId="TableStyle">
            <w:name w:val="Table Style"/>
            <w:tblPr>
              <w:tblBorders>
                 <w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/>
              </w:tblBorders>
            </w:tblPr>
          </w:style>
        </w:styles>
        <w:body>
          <w:tbl>
            <w:tblPr>
                <w:tblStyle w:val="TableStyle"/>
            </w:tblPr>
            <w:tblGrid>
                <w:gridCol w:w="100" />
                <w:gridCol w:w="1024" />
            </w:tblGrid>
            <w:tr>
                <w:tc><w:p><w:r><w:t>ID</w:t></w:r></w:p></w:tc>
                <w:tc><w:p><w:r><w:t>Description</w:t></w:r></w:p></w:tc>   
            </w:tr> 
            <xsl:apply-templates select="items/item">
                <xsl:sort select="id" order="ascending"/>
            </xsl:apply-templates>
          </w:tbl>
        </w:body>
      </w:wordDocument>
    </xsl:template>
    
    <xsl:template match="items/item">
        <w:tr>
            <w:tc><w:p><w:r><w:t>
                <xsl:value-of select="id"/>
            </w:t></w:r></w:p></w:tc>
            <w:tc><w:p><w:r><w:t>
                <xsl:value-of select="description"/>
            </w:t></w:r></w:p></w:tc>
        </w:tr>
    </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a xml file which I need to open with Microsoft Word 2007.
I have an XML file whose contents I want to sort by document order
I have a xml file whose content is <?xml version=1.0 encoding=UTF-8?> <ReturnMessage> <root>ReturnMessage</root> <cancelMessage>Request
I have an XML file that looks like <?xml version=1.0> <playlist> <name>My Playlist</name> <song>
I have an XML file that reads like this <abc> <ab>value</ab> <aa>time</aa> <ac>money</ac> </abc>
I have an XML file that I'm trying to read from here , and
I have an XML file that is well formed and valid (matched with an
I have a WCF service that is being used to generate an XML file
I have a TextView whose contents are copied from a text file. Now each
I have a xml file roughly like this: <batch> <header> <headerStuff /> </header> <contents>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.