473,762 Members | 7,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSL ".NET DataSet" to "Excel": Detect missing column

115 New Member
Hi,

Im not very experienced with XSL, this is my first run in with it. I found an XSL file that converts a dataset to an excel readable format.

The problem I have is when the dataset has a null value for a column, it does not add an empty element for the column. Is there any way I can detect this?

Excel.xsl:
Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet version="1.0" 
  2.   xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  3.   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  4.   xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  5.   xmlns:user="urn:my-scripts"
  6.   xmlns:o="urn:schemas-microsoft-com:office:office"
  7.   xmlns:x="urn:schemas-microsoft-com:office:excel"
  8.   xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" > 
  9.  
  10. <xsl:template match="/">
  11.   <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  12.     xmlns:o="urn:schemas-microsoft-com:office:office"
  13.     xmlns:x="urn:schemas-microsoft-com:office:excel"
  14.     xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
  15.     xmlns:html="http://www.w3.org/TR/REC-html40">
  16.       <xsl:apply-templates/>
  17.   </Workbook>
  18. </xsl:template>
  19.  
  20. <xsl:template match="/*">
  21.   <Worksheet>
  22.     <xsl:attribute name="ss:Name">
  23.     <xsl:value-of select="local-name(/*/*)"/>
  24.     </xsl:attribute>
  25.     <Table x:FullColumns="1" x:FullRows="1">
  26.  
  27.       <xsl:for-each select="*[position() = 1]/*">
  28.         <Column ss:Width="120"/>
  29.       </xsl:for-each>      
  30.  
  31.       <Row>
  32.         <xsl:for-each select="*[position() = 1]/*">
  33.           <Cell><Data ss:Type="String">
  34.           <xsl:value-of select="local-name()"/>
  35.           </Data></Cell>
  36.         </xsl:for-each>
  37.       </Row>
  38.       <xsl:apply-templates/>
  39.     </Table>
  40.   </Worksheet>
  41. </xsl:template>
  42.  
  43.  
  44. <xsl:template match="/*/*">
  45.   <Row>
  46.     <xsl:apply-templates/>
  47.   </Row>
  48. </xsl:template>
  49.  
  50.  
  51. <xsl:template match="/*/*/*">
  52.   <Cell>
  53.     <Data ss:Type="String">
  54.           <xsl:value-of select="."/>
  55.     </Data>
  56.   </Cell>
  57. </xsl:template>
  58.  
  59. </xsl:stylesheet>
May 13 '08 #1
4 3623
jkmyoung
2,057 Recognized Expert Top Contributor
Can we see your source xml, and an example of where the missing cell is causing a problem?
May 13 '08 #2
ShadowLocke
115 New Member
Can we see your source xml, and an example of where the missing cell is causing a problem?
Here is what the xml looks like:

Expand|Select|Wrap|Line Numbers
  1. <NewDataSet>
  2.     <DataTable>
  3.         <FULL_NAME>Actual Data Removed</FULL_NAME>
  4.         <SPECIALTY>Actual Data Removed</SPECIALTY>
  5.         <LOCATION>Actual Data Removed</LOCATION>
  6.         <ENTRY_DATE>Actual Data Removed</ENTRY_DATE>
  7.         <ACTION>Actual Data Removed</ACTION>
  8.     </DataTable>
  9.  
  10.     <DataTable>
  11.         <FULL_NAME>Actual Data Removed</FULL_NAME>
  12.         <LOCATION>Actual Data Removed</LOCATION>
  13.         <ENTRY_DATE>Actual Data Removed</ENTRY_DATE>
  14.         <ACTION>Actual Data Removed</ACTION>
  15.     </DataTable>
  16.  
  17.     <DataTable>
  18.         <FULL_NAME>Actual Data Removed</FULL_NAME>
  19.         <SPECIALTY>Actual Data Removed</SPECIALTY>
  20.         <LOCATION>Actual Data Removed</LOCATION>
  21.         <ENTRY_DATE>Actual Data Removed</ENTRY_DATE>
  22.         <ACTION>Actual Data Removed</ACTION>
  23.     </DataTable>
  24. </NewDataSet>
(Second <datatable> is missing specialty)

Actually, after seeing this I am thinking its not possible. What I did to solve my problem is went to the actual SQL select and used DECODE to check for nulls and return an empty string instead.

Still, if you think it can be done let me know!

Thanks for your time!
May 13 '08 #3
jkmyoung
2,057 Recognized Expert Top Contributor
You can do this with a set of defined headers. Eg:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="/*/*">
  2.   <Row>
  3.      <xsl:call-template name="Data">
  4.         <xsl:with-param name="nodename" select="'FULL_NAME'"/>
  5.      </xsl:call-template>
  6.      <xsl:call-template name="Data">
  7.         <xsl:with-param name="nodename" select="'SPECIALTY"/>
  8.      </xsl:call-template>
  9.      <xsl:call-template name="Data">
  10.         <xsl:with-param name="nodename" select="'LOCATION'"/>
  11.      </xsl:call-template>
  12.      <xsl:call-template name="Data">
  13.         <xsl:with-param name="nodename" select="'ENTRY_DATE'"/>
  14.      </xsl:call-template>
  15.      <xsl:call-template name="Data">
  16.         <xsl:with-param name="nodename" select="'ACTION"/>
  17.      </xsl:call-template>
  18.   </Row>
  19. </xsl:template>
  20. <xsl:template name="Data">
  21. <xsl:param name="nodename"/>
  22.   <Cell>
  23.     <Data ss:Type="String">
  24.           <xsl:value-of select="*[local-name() = $nodename]"/>
  25.     </Data>
  26.   </Cell>
  27. </xsl:template>
  28.  
Or if you have the headers specifically sent to you (in a seperate xml file, or somewhere in the same file) you can also do the same type of thing, though the code is somewhat more complicated. Eg: this is where the headers are in the xslt file, although they can be gotten from elsewhere.
Expand|Select|Wrap|Line Numbers
  1. <my:mapping xmlns:my="internal">
  2.         <data name="FULL_NAME"/>
  3.         <data name="SPECIALTY"/>
  4.         <data name="LOCATION"/>
  5.         <data name="ENTRY_DATE"/>
  6.         <data name="ACTION"/>
  7. </my:mapping>
  8. <xsl:template match="/*/*">
  9.   <Row>
  10.     <xsl:variable name="self" select="."/>
  11.     <xsl:for-each select="document('')//data">
  12.       <xsl:variable name="name" select="@name"/>
  13.       <xsl:apply-templates select="$self\*[local-name() = $name]"/>
  14.     </xsl:for-each>
  15.   </Row>
  16. </xsl:template>
  17.  
May 14 '08 #4
ShadowLocke
115 New Member
Interesting. I'm gonna give another go at it later on this week. The predefined headers might be the way I go. Possibly creating the XSL sheet on the fly as oppossed to using a predfined file.
May 14 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
21174
by: Jerry O | last post by:
Hi , I have my asp successfully creating excel file viewable through IE using the header: Response.ContentType = "application/vnd.ms-excel" If the user does not have excel installed they get a IE pop up that downloads the asp page in question.
3
11932
by: John | last post by:
Is there a way to code the button that's available in the query window--microsoft excel icon that exports to excel. I know transferspreadsheet will do this---but I want the query, which is in a pivot table view, to be exported as a pivot, not just a data list. Does this code exist? Is it transferspreadsheet but with a twist?
2
3610
by: nutthatch | last post by:
I want to be able to import an Excel spreadsheet into Access 2K using the macro command Transferspreadsheet. However, the file I am importing (over which I have no control) contains some records that are "dirty" i.e. the field contents do not comply with the expected format (date/time) and they end up in a seperate table of import errors. (The records in "error" are actually empty fields.) This is a regular event and I do not want to...
5
9372
by: KC | last post by:
Hi, I have code similar to this.. Dim xlApp As Object xlApp = CreateObject("Excel.Application", "\\MyServer") The call is from a asp.net (Intranet) application. \\Myserver is a network computer in the same domain as web server. The only way I can get this call worked is when I add the user who logs on to the web site as Administrators. I need to get this working without having to make the user administrator. Any suggestion?
1
3269
by: Benny Ng | last post by:
Hi,All, Export Method: ------------------------------------------------------------------------- strFileNameExport = "Results" Response.Clear() Response.Buffer = True Response.ContentType ="application/vnd.ms-excel" 'application/msword
1
1396
by: Michael Twua | last post by:
In asp.net with vb.net,I can't create a excel object,such as excel.application,excel.workBook,excel.workSheet. It displayed that "System.UnauthorizedAccessException Refuse Access". I have import "Microsoft Excel9.0 Object Library", aspnet user have all data operation. What Problem it is?How to resolve this problem?
2
15505
by: CVerma | last post by:
I'm using an html input control (System.web.UI.HTMLControls.HTMLInputFile) to upload files such as msword, excel, jpg, and pdf. I have the encType property set in the form: encType="multipart/form-data" <INPUT id="UploadFile" type="file" name="UploadFile" runat="server"> Private Sub btnUploadFile_Click(ByVal sender As System.Object, ByVal e
1
2303
by: Michael Tkachev | last post by:
Hi Everybody, I created an Excel file in the ASP.Net. When I wrote this file on the disk I tryed to release COM objects. But I couldn't do it. When my method finished an "Excel" process exists in the memory. So, I would like to kill an "Excel" process and for it I need to know a ProcessID or something like this. Who knows how can I get a processID or release COM objects? Excel.ApplicationClass a = new Excel.ApplicationClass();
0
5673
by: Microsoft NewsGroups | last post by:
I am creating a TAB delimited file with .XLS extention using the Response.ContentType = "application/ms-excel" method. Normally I would place this on it's own form and delete all the HTML in the ASPX page - otherwise the aspx code gets appended to the end of the file out put to Excel. How do I produce the same output from a page where I cannot simply delete all the HTML code (must leave buttons and other objects intact)? In other words how...
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9377
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.