By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,610 Members | 2,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,610 IT Pros & Developers. It's quick & easy.

XML + XSL + JAVA= Excel Help me to convert please! :D

budigila
P: 1
Hiya peeps,

Okies, I have been trying to work this out for a while now to no avail... I am a beginner to this whole coding thing but have made great strides in my project. Basically what I am trying to do is to convert an .xml using a .xsl to and using a java script to output it into a readable format within excel. I have been able to successfully use a javascript to combine my .xml and .xsl but cannot figure out how to have it output to excel. Please help if possible!

And if thats easy enough what about fomatting my time and date in (DD/MM/YY HH:mm:ss)

Thanks in advance!

Here are the files I have been working with:

JAVASCRIPT

<%
response.setContentType("application/vnd.ms-excel");
%>


<html>
<body>

<script type="text/javascript">
//Load XML
var xml=new ActiveXObject("Microsoft.XMLDOM")
xml.async=false
xml.load("test.xml")

//Load the XSL
var xsl=new ActiveXObject("Microsoft.XMLDOM")
xsl.async=false
xsl.load("test.xsl")

//Transform
document.write(xml.transformNode(xsl))

</script>

</body>
</html>


XSL FILE

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -->
<html>

<head>
<link rel="stylesheet" type="text/css" href="C:\test.css" />
</head>

<body>

<div id="container">

<div class="tableContainer">

<table class="report">

<tbody>

<xsl:for-each select="fasting/pickups/pickup">

<tr>

<td class="Passing"><xsl:text/></td>

<td class="Type"><xsl:text/>Pickup</td>

<td class="Object"><xsl:value-of select="@id"/></td>

<td class="Begining"><xsl:value-of select="@begin"/></td>

<td class="Halting"><xsl:value-of select="@halt"/></td>

<td class="Length"><xsl:text/></td>

<td class="Status"><xsl:text/>X</td>

<td class="Begining"><xsl:text/></td>

<td class="Halting"><xsl:text/></td>

<td class="Length"><xsl:text/></td>

<td class="FRP"><xsl:value-of select="@frp"/></td>

<td class="Dome"><xsl:value-of select="load/@dome"/></td>

<td class="Timely"><xsl:value-of select="load/@timely"/></td>

<td class="Pri"><xsl:text/></td>

<td class="Notes"><xsl:text/></td>

</tr>

</xsl:for-each>

<xsl:for-each select="fasting/putdown/airline">

<tr>

<td class="Passing"><xsl:text/></td>

<td class="Type"><xsl:text>Putdown </xsl:text>

<xsl:value-of select="@id"/></td>

<td class="Object"><xsl:value-of select="file/@id"/></td>

<td class="Begining"><xsl:value-of select="@begin"/></td>

<td class="Halting"><xsl:value-of select="@halt"/></td>

<td class="Length"><xsl:text/></td>

<td class="Status"><xsl:text/>X</td>

<td class="Begining"><xsl:text/></td>

<td class="Halting"><xsl:text/></td>

<td class="Length"><xsl:text/></td>

<td class="PRF"><xsl:value-of select="@prf"/></td>

<td class="Dome"><xsl:value-of select="load/@dome"/></td>

<td class="Timely"><xsl:value-of select="load/@timely"/></td>

<td class="Prioroity"><xsl:text/></td>

<td class="Notes"><xsl:text/></td>

</tr>

</xsl:for-each>

</tbody>

</table>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

XML FILE

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="C:\Test.xsl" ?>
<fasting begin="09 27 2007 15:46:59" halt="09 28 2007 15:37:43">
<pickups>
<pickup id="data4321093" begin="09 27 2007 10:46:59" halt="09 27 2007 10:47:05" frp="false">
<load id="X" dome="005" timely="BB"></load>
</pickup>
<pickup id="data123411" begin="09 27 2007 11:43:16" halt="09 27 2007 11:55:49" frp="false">
<load id="Y" dome="003" timely="BB"></load>
</pickup>
<pickup id="data432113" begin="09 27 2007 12:26:34" halt="09 27 2007 12:26:40" frp="false">
<load id="X" dome="001" timely="BB"></load>
</pickup>
<pickup id="data1234111" begin="09 27 2007 13:35:30" halt="09 27 2007 13:44:54" frp="false">
<load id="Y" dome="002" timely="BB"></load>
</pickup>
<pickup id="data4321121" begin="09 27 2007 14:03:54" halt="09 27 2007 14:11:19" frp="false">
<load id="X" dome="102" timely="BB"></load>
</pickup>
<pickup id="data1234131" begin="09 27 2007 20:43:41" halt="09 27 2007 21:01:18" frp="false">
<load id="Y" dome="001" timely="BB"></load>
</pickup>
<pickup id="data1234141" begin="09 27 2007 22:37:54" halt="09 27 2007 22:41:10" frp="false">
<load id="Y" dome="004" timely="BB"></load>
</pickup>
<pickup id="data1234011" begin="09 28 2007 01:59:33" halt="09 28 2007 02:09:02" frp="false">
<load id="Y" dome="002" timely="BB"></load>
</pickup>
<pickup id="data4321013" begin="09 28 2007 03:45:57" halt="09 28 2007 03:46:03" frp="false">
<load id="X" dome="004" timely="BB"></load>
</pickup>
<pickup id="data4321021" begin="09 28 2007 04:40:54" halt="09 28 2007 04:48:49" frp="false">
<load id="X" dome="102" timely="BB"></load>
</pickup>
<pickup id="data4321023" begin="09 28 2007 05:31:04" halt="09 28 2007 05:31:10" frp="false">
<load id="X" dome="001" timely="BB"></load>
</pickup>

<pickup id="data1234081" begin="09 28 2007 14:15:45" halt="09 28 2007 14:19:01" frp="false">
<load id="Y" dome="004" timely="BB"></load>
</pickup>
<pickup id="data4321083" begin="09 28 2007 14:57:57" halt="09 28 2007 14:58:03" frp="false">
<load id="X" dome="001" timely="BB"></load>
</pickup>
<pickup id="data4321091" begin="09 28 2007 15:06:32" halt="09 28 2007 15:06:38" frp="false">
<load id="X" dome="101" timely="BB"></load>
</pickup>
<pickup id="data4321093" begin="09 28 2007 15:37:37" halt="09 28 2007 15:37:43" frp="false">
<load id="X" dome="001" timely="BB"></load>
</pickup>
</pickups>
<putdown>
<airline id="R" begin="09 27 2007 16:11:37" halt="09 27 2007 16:26:37">
<file id="data4321093" last="true"></file>
</airline>
<airline id="R" begin="09 28 2007 00:42:55" halt="09 28 2007 00:57:55"></airline>
<airline id="R" begin="09 28 2007 01:26:30" halt="09 28 2007 01:38:34">
<file id="data1234011" last="true"></file>
</airline>
<airline id="R" begin="09 28 2007 02:25:10" halt="09 28 2007 02:40:10">
<file id="data4321013" last="true"></file>
</airline>
<airline id="R" begin="09 28 2007 03:08:45" halt="09 28 2007 03:19:53">
<file id="data4321021"></file>
</airline>
<airline id="R" begin="09 28 2007 04:07:26" halt="09 28 2007 04:22:26">
<file id="data4321021" last="true"></file>
<file id="data4321023" last="true"></file>
</airline>
<airline id="R" begin="09 28 2007 04:51:01" halt="09 28 2007 05:02:26">
<file id="data4321032" last="true"></file>
</airline>
<airline id="R" begin="09 28 2007 05:49:42" halt="09 28 2007 06:04:42">
<file id="data4321033" last="true"></file>
</airline>
<airline id="R" begin="09 28 2007 06:33:16" halt="09 28 2007 06:48:00">
<file id="data1234041" last="true"></file>
</airline>
<airline id="R" begin="09 28 2007 07:31:57" halt="09 28 2007 07:46:57">
<file id="data4321042" last="true"></file>
</airline>
<airline id="R" begin="09 28 2007 08:16:00" halt="09 28 2007 08:30:42"></airline>
<airline id="R" begin="09 28 2007 09:57:48" halt="09 28 2007 10:10:09">
<file id="data4321052" last="true"></file>
<file id="A807" last="true"></file>
</airline>
<airline id="R" begin="09 28 2007 10:56:28" halt="09 28 2007 11:11:28">
<file id="data4321061" last="true"></file>
</airline>
<airline id="R" begin="09 28 2007 11:40:03" halt="09 28 2007 11:51:18"></airline>
<airline id="R" begin="09 28 2007 12:38:44" halt="09 28 2007 12:53:44">
<file id="data1234071" last="true"></file>
</airline>
<airline id="R" begin="09 28 2007 14:20:59" halt="09 28 2007 14:35:59">
<file id="data1234081" last="true"></file>
<file id="data4321083" last="true"></file>
</airline>
<airline id="R" begin="09 28 2007 15:04:34" halt="09 28 2007 15:19:25"></airline>
</putdown>
</fasting>
Oct 9 '07 #1
Share this Question
Share on Google+
2 Replies


MarkoKlacar
Expert 100+
P: 296
Hi,

I think you should look at how an Excel file is constructed "inside" so to speak. What you'll probably do after this is create a new XSL transformation that makes it format the way Excel likes it.

Hope this helped
Oct 9 '07 #2

jkmyoung
Expert 100+
P: 2,057
A minimalist Excel sheet in xml form looks like the following:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <?mso-application progid="Excel.Sheet"?>
  3. <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  4.  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
  5.  <Worksheet ss:Name="Sheet1">
  6.   <Table>
  7.    <Row>
  8.     <Cell><Data ss:Type="String">a</Data></Cell>
  9.     <Cell><Data ss:Type="String">b</Data></Cell>
  10.    </Row>
  11.    <Row>
  12.     <Cell><Data ss:Type="String">c</Data></Cell>
  13.     <Cell><Data ss:Type="String">d</Data></Cell>
  14.    </Row>
  15.   </Table>
  16.  </Worksheet>
  17. </Workbook>
  18.  
Use this as your shell in your main template.
Then in your stylesheet, do several replaces.

Replace:
<tr> with <Row>
</tr> with </Row>
<td> with <Cell><Data ss:Type="String"> (or pick a different datatype if you want).
</td> with </Data></Cell>

Hope this gives you a good starting point.
Note, if you open this file in excel and resave, it will add more information. The layout provided is minimal.
Oct 9 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.