Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Handing dataset type from XML to Xls for Excel
Message
 
À
02/05/2006 14:31:10
Information générale
Forum:
ASP.NET
Catégorie:
XML
Divers
Thread ID:
01118226
Message ID:
01118530
Vues:
17
Hi Michel,

The blank line is being generated because the template that matches the XPath expression "/*/*/*" selects also the nodes into the "xs:schema" element, which is probably not the intended behavior.

I have rewriten the XSL document in order to correct this and to make it a little mode structured. Please see if it is according to your needs.
<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:for-each select="/NewDataSet/Temp" >
					<xsl:call-template name="ProcessDataRows">
						<xsl:with-param name="tempElement" select="current()"/>
					</xsl:call-template>
				</xsl:for-each>

			</Table>
		</Worksheet>
	</xsl:template>


	<xsl:template name="ProcessDataRows">
		<xsl:param name="tempElement" />
		<Row>
			<xsl:for-each select="$tempElement/*">
				<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:for-each>
		</Row>
	</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