Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Handing dataset type from XML to Xls for Excel
Message
De
01/05/2006 21:01:22
 
Information générale
Forum:
ASP.NET
Catégorie:
XML
Divers
Thread ID:
01118226
Message ID:
01118251
Vues:
18
>Since we are having different results for the same XML/XSL files I am wondering if we are using different XSL Processors. I am using Visual Studio 2005 XSLT debugger in my tests. How are you processing the XSL file? If you are doing that programatically, could you please show us your code?

I saw that in your result, the field headers are not the same those two headers I have. You showed one header only having the name element. But, I don't think this could be a factor for our results.

The code to transform is as follow:
        ' Export a dataset into an Excel spreadsheet
        ' expO1 DataSet
        ' expC1 Full path of the file to save
        Public Function ExportToExcel(ByVal toDataSet As DataSet, ByVal tcFile As String) As Boolean

            ' Read the dataset in a XmlDataDocument
            Dim loXmlDataDoc As XmlDataDocument = New XmlDataDocument(toDataSet)

            Dim loXslCompiledTransform As Xsl.XslCompiledTransform = New Xsl.XslCompiledTransform

            ' Get the Excel stylesheet into memory
            Dim loMemorySteam As New FileStream(oApp.cHttpFat + "App_GlobalResources\Excel.xsl", FileMode.Open, FileAccess.Read)

            Dim loXmlTextReader As XmlTextReader = New XmlTextReader(loMemorySteam)
            loXslCompiledTransform.Load(loXmlTextReader, Nothing, Nothing)
            Dim loStringWriter As New StringWriter()
            loXslCompiledTransform.Transform(loXmlDataDoc, Nothing, loStringWriter)

            ' Try to save the file
            If Not oApp.CreateFile(loStringWriter.ToString(), tcFile) Then
                Return False
            End If

            Return True
        End Function
So again, just to be sure, Excel.xsl is as follow:
<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="*[position() = 1]/*">
						<Cell>
							<Data ss:Type="String">
								<xsl:value-of select="local-name()"/>
							</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=local-name(current()/>
					</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>
I cannot use the test Xml with the two records because the code I am using to transform need to work with a dataset. Or, do you know a way to adjust that code to read from the test Xml, the one with the two records, so we can test exactly with the same components?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform