Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Handing dataset type from XML to Xls for Excel
Message
 
À
01/05/2006 21:29:50
Information générale
Forum:
ASP.NET
Catégorie:
XML
Divers
Thread ID:
01118226
Message ID:
01118264
Vues:
22
Hi Michel,

The problem with the headers seemed to be related to the XPath expression used in the template that processes them.

I get the correct results by changing this line:
<xsl:for-each select="*[position() = 1]/*">
with this:
<xsl:for-each select="/NewDataSet/Temp[position() = 1]/*">
To avoid any confusion I am copying the full Xsl document below:
<xsl:stylesheet version="1.0"
	xmlns="urn:schemas-microsoft-com:office:spreadsheet"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:msxsl="urn:schemas-microsoft-com:xslt"
	xmlns:user="urn:my-scripts"
	xmlns:o="urn:schemas-microsoft-com:office:office"
	xmlns:x="urn:schemas-microsoft-com:office:excel"
	xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" 
	xmlns:xs="http://www.w3.org/2001/XMLSchema" 
	>

	<xsl:template match="/">
		<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
		  xmlns:o="urn:schemas-microsoft-com:office:office"
		  xmlns:x="urn:schemas-microsoft-com:office:excel"
		  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
		  xmlns:html="http://www.w3.org/TR/REC-html40">
			<xsl:apply-templates/>
		</Workbook>
	</xsl:template>


	<xsl:template match="/*">
		<Worksheet>
			<xsl:attribute name="ss:Name">
				<xsl:value-of select="local-name(/*/*)"/>
			</xsl:attribute>
			<Table x:FullColumns="1" x:FullRows="1">
				<Row>
					<xsl:for-each select="/NewDataSet/Temp[position() = 1]/*">
						<Cell>
							<Data ss:Type="String">
								<xsl:value-of select="local-name(current())"/>
							</Data>
						</Cell>
					</xsl:for-each>
				</Row>
				<xsl:apply-templates/>
			</Table>
		</Worksheet>
	</xsl:template>


	<xsl:template match="/*/*">
		<Row>
			<xsl:apply-templates/>
		</Row>
	</xsl:template>


	<xsl:template match="/*/*/*">
		<Cell>
			<xsl:choose>
				<xsl:when test="//xs:element[ @name = local-name(current()) ]/@type = 'xs:decimal'">
					<Data ss:Type="Number">
						<xsl:value-of select="."/>
					</Data>
				</xsl:when>
				<xsl:when test="//xs:element[ @name = local-name(current()) ]/@type = 'xs:string'">
					<Data ss:Type="String">
						<xsl:value-of select="."/>
					</Data>
				</xsl:when>
			</xsl:choose>
		</Cell>
	</xsl:template>


</xsl:stylesheet>
-----
Fabio Vazquez
http://www.fabiovazquez.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform