Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: Convert XMl to Excel using XLST

From: LeonFord@-----------.---------.---
To: NULL
Date: 1/5/2006 8:10:00 AM
I just ran through this exercise and this is what I found.  Assuming you are 
using Office 2002 or above, a good start is to create your desired Excel 
spreadsheet look with all of the column headers and column formats then save 
the file as XML.  This will create the basic XML file you need as a starting 
point.  Then you turn the file into a XSL style sheet by adding the following 
lines to the top

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml"/>
  <xsl:preserve-space elements="*"/>
<xsl:template match="/">

and add the corresponding end tags to the end of the file.

</xsl:template>
</xsl:stylesheet>

Save the file with an extension of .XSL and use this in your XSL 
Transformation.  The guts of the file are similar to what you have already.

Leon

"mark.macumber@g..." wrote:

> I have been Scowering the net to try to find how to convert a simple
> XML file to an Excel workbook using XSLT. I have a basic outline
> working, But I need extra help. My XML is as follows:
> 
> <?xml version="1.0"?>
> <?xml-stylesheet type='text/xsl' href='conditionReport.xslt'?>
> <AreasRoot>
> 	<room name="Entrance Hall">
> 		<item name="Doors">
> 			<roomIndex>0</roomIndex>
> 			<conditionBefore />
> 			<conditionAfter />
> 			<commentsBefore />
> 			<commentsAfter />
> 		</item>
> 		<item name="Security Door">
> 			<roomIndex>0</roomIndex>
> 			<conditionBefore>F</conditionBefore>
> 			<conditionAfter />
> 			<commentsBefore />
> 			<commentsAfter />
> 		</item>
> 	</room>
> 
> 	<userDetails>
> 		<tennant address="123 Fake Street"
>                               name="Mark"
>                               landlord="DCK"
>                               leaseDate="11/11/2005" />
> 	</userDetails>
> </AreasRoot>
> 
> 
> *********************************************************************************
> End of XML - this is not part of the XML
> *********************************************************************************
> 
> and here is the XSLT document I use to format the above: (called
> conditionReport.xslt)
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	<xsl:template match="/">
> 			<html>
> 				<head>
> 					<style>
> 
> 					</style>
> 				</head>
> 				<body>
> 					<table border="1">
> 						<colgroup width="20" align="center"></colgroup>
> 						<colgroup width="135" align="left"></colgroup>
> 						<colgroup width="25" align="left"></colgroup>
> 						<colgroup width="25" align="left"></colgroup>
> 						<colgroup width="25" align="left"></colgroup>
> 						<colgroup width="250" align="left"></colgroup>
> 						<colgroup width="25" align="left"></colgroup>
> 						<colgroup width="25" align="left"></colgroup>
> 						<colgroup width="25" align="left"></colgroup>
> 						<colgroup width="250" align="left"></colgroup>
> 						<td>Room</td>
> 						<td>Item</td>
> 						<td>Good</td>
> 						<td>Fair</td>
> 						<td>Poor</td>
> 						<td>Other Items and Comments</td>
> 						<td>Good</td>
> 						<td>Fair</td>
> 						<td>Poor</td>
> 						<td>Other Items and Comments</td>
> 						<xsl:for-each select="AreasRoot/room">
> 							<tr>
> 								<td valign="top" rowspan="{count(item)}"
> reference-orientation="90">
> 									<b>
> 										<xsl:value-of select="@name"/>
> 									</b>
> 								</td>
> 								<xsl:for-each select="item">
> 									<td>
> 										<xsl:value-of select="@name"/>
> 									</td>
> 									<td>
> 										<xsl:if test="./conditionBefore = 'G' ">
> 											x
> 										</xsl:if>
> 									</td>
> 									<td>
> 										<xsl:if test="./conditionBefore = 'F' ">
> 											x
> 										</xsl:if>
> 									</td>
> 									<td>
> 										<xsl:if test="./conditionBefore = 'P' ">
> 											x
> 										</xsl:if>
> 									</td>
> 									<td>
> 										<xsl:value-of select="commentsBefore"/>
> 									</td>
> 									<td>
> 										<xsl:if test="./conditionAfter = 'G' ">
> 											x
> 										</xsl:if>
> 									</td>
> 									<td>
> 										<xsl:if test="./conditionAfter = 'G' ">
> 											x
> 										</xsl:if>
> 									</td>
> 									<td>
> 										<xsl:if test="./conditionAfter = 'G' ">
> 											x
> 										</xsl:if>
> 									</td>
> 									<td>
> 										<xsl:value-of select="commentsAfter"/>
> 									</td>
> 									<xsl:if test="position() != last()">
> 										<xsl:text disable-output-escaping="yes"><tr></xsl:text>
> 									</xsl:if>
> 								</xsl:for-each>
> 							</tr>
> 						</xsl:for-each>
> 					</table>
> 				</body>
> 			</html>
> 	</xsl:template>
> </xsl:stylesheet>
> 
> 
> ****************************************************************************
> End of XSLT document - this is not part of the XSLT document
> ****************************************************************************
> 
> 
> so that works ok so far. I need some basic formatting done, but that
> can be worried about at a leter date. As you can see in the XML there
> is a element called userDetails. I need for the information stored in
> this node the on a different worksheet, how do i do that? I just cant
> seem to find an answer anywhere its driving me nuts!
> 
> Please help.
> Cheers,
> Mark
> 
> 


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent