How can I use XSLT and XML to compose Excel , which has dynamic fields?

Posted on 2007-04-10
Last Modified: 2013-11-18
Hi All,
  My XML file has few static and few dynamic elements, like name is static, grap points is dynamic means its computed by average of "input" ( This I would do it from my application).

  <name>Manjesh</name>                  // Static
  <profession>Eng</profession>            // Static      
  <gradpoints>12</gradpoints>  // Dynamic field calculated by computing the average of input
    <input>10</input>            // Static
    <input>12</input>            // Static
    <input>14</input>            // Static

Excel Sheet
Name            Profession            GradPoints
Manjesh            Engg            12

Once its done I would like to show only few relavent fields in my excel as mentioned above. Unfortunatley I dont have enough time to experiment XSLT and mapping to Excel. So if any expert can give the XSLT and steps for importing the same to excel .

Thanks for your earliest attention.

Question by:Manjesh
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 60

Accepted Solution

Geert Bormans earned 50 total points
ID: 18887672
There are several ways to get to Excel from XML.
Depending on your needs you could use an XML schema, bind it to a table and import the XML directly. Or you could use special tools dediacted to writing Excel files.

If you want to use XSLT, again you have some options (though you can't write binary Excel)
You could write the Excel XML format. You then have most of the bells and whistles, but it is a complex format.
You can also write simple HTML tables, in order to pass some formatting.
In simple cases, you can write tab seperated text, which you then import in Excel.

That is what this example does

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="" version="1.0">
    <xsl:param name="newline" select="'&#13;&#10;'"/>
    <xsl:param name="tab" select="'&#9;'"/>
    <xsl:output method="text"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="/">
        <xsl:value-of select="$tab"/>
        <xsl:value-of select="$tab"/>
        <xsl:value-of select="$newline"/>
        <xsl:apply-templates select="//userdata"/>
    <xsl:template match="userdata">
        <xsl:value-of select="name"/>
        <xsl:value-of select="$tab"/>
        <xsl:value-of select="profession"/>
        <xsl:value-of select="$tab"/>
        <xsl:value-of select="gradpoints"/>
        <xsl:value-of select="$newline"/>


LVL 60

Expert Comment

by:Geert Bormans
ID: 18887720
I don't know how much effort you do for calculating the mean,
but this is straightforward in XSLT

   <xsl:template match="userdata">
        <xsl:value-of select="name"/>
        <xsl:value-of select="$tab"/>
        <xsl:value-of select="profession"/>
        <xsl:value-of select="$tab"/>
        <xsl:value-of select="sum(acadrecord/input) div count(acadrecord/input)"/>
        <xsl:value-of select="$newline"/>

Author Comment

ID: 18887870
Thanks for your quik reply.

Assuming I have the XML  and XSLT as mentioned above , How can I show the data in Excel?

Like how can I import XSLT in excel and get the view of my data ?

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

LVL 60

Expert Comment

by:Geert Bormans
ID: 18887907
use a commandline XSLT processor, or set the proces up in ASP
save the result file as *.xls and double-click
or serve the result out with a ms-application-excel mime-type

Author Comment

ID: 18888270
Finally I found a VB Script which can convert XML( XSL ) to CSV file. But instead of being comma separeated it separated by ;

When I run the script its seperated by ";(Semicolon)" instead od Comma. Experts any clue how to tweak the code , to make it comma seperated.


<?xml version="1.0"?>
<xsl:stylesheet version = "1.0"      xmlns:xsl = "">
<xsl:output method="text"/>
<xsl:strip-space elements = "gazetteer"/>
<xsl:template match="place">
<xsl:text/><xsl:value-of select="normalize-space(name)"/>,<xsl:text/>
<xsl:value-of select="normalize-space(county)"/>,<xsl:text/>
<xsl:value-of select="normalize-space(ngr/easting)"/>,<xsl:text/>
<xsl:value-of select="normalize-space(ngr/northing)"/>,<xsl:text/>
<xsl:value-of select="normalize-space(geographical/latitude)"/>,<xsl:text/>
<xsl:value-of select="normalize-space(geographical/longitude)"/><xsl:text/>          
<xsl:text disable-output-escaping = "yes" >


<?xml version = "1.0"?>
    <county>West Midlands</county>


  Dim xmlSource
  Dim xmlXForm
  Dim strErr
  Dim strResult
  Dim fso , file
  Dim strPath
  Const ForReading = 1
  Const ForWriting = 2
  Const ForAppending = 8
  Set xmlSource = CreateObject("MSXML.DOMDocument")
  Set xmlXForm = CreateObject("MSXML.DOMDocument")
  xmlSource.validateOnParse = True
  xmlXForm.validateOnParse = True
  xmlSource.async = False
  xmlXForm.async = False
  xmlSource.Load "c:\test\testme.xml"  ' This loads the text that I want to transform
  xmlXForm.Load "c:\test\testme.xsl" ' This loads the XSLT transform
  strResult = xmlSource.transformNode(xmlXForm) ' This transforms the data in xmlSource
  Set fso = CreateObject("Scripting.FileSystemObject")
  strPath = "c:\test\testme.csv"
  Set file = fso.opentextfile(strPath, ForWriting, True)

  file.write strResult
  Set file = Nothing
  Set fso = Nothing
  Set xmlSource = Nothing
  Set xmlXForm = Nothing

Thanks for your earliest attention.


Manjesh Gowda S H
LVL 60

Expert Comment

by:Geert Bormans
ID: 18888291
If I look at the XSLT, I would expect the seperator being ','
because that is what is in the code

Have you tried using your own XML, with my XSLT in combination with this VB script?
It should give you what you need



Author Comment

ID: 18888345
Hi Gertone,
  Thanks for your quick reply and handy solution, I was able to get it done through VB Script.

Thanks a lot again.
LVL 60

Expert Comment

by:Geert Bormans
ID: 18888459

Author Comment

ID: 18896594
Hi Greet,
  I got the thing workign fine...but a small hitch. I have the XSL and XML file and I want to open it excel, I dont want to create a CSV file using VB Script. I want to directly import in Excel. Any suggestions?

Thanks for your earliest response.


Manjesh Gowda S H

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question