Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Convert XMl to Excel using XLST

From: mark.macumber@-----.---
To: NULL
Date: 1/4/2006 8:34:00 PM
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">&lt;tr&gt;</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