Re: Re: Complex expression
Andrew, I was really hoping for an easy fix (10 lines or so total). I actually do process all good-date and bad-date rows in the template which calls the template which I posted before. So the difference in the call to the buildstatement template is just a table name. Since that column is nullable, we decided to insert NULL instead of skipping column in insert. The real question I have is what is a correct syntax for the expression " if type of Excel cell called Start_Date <xsl:when test='sht:Cell[sht:Name="Start_Date"]/@ValueType != "DATE"'> or maybe <xsl:when test='not(sht:Cell/sht:Name[.="Start_Date"]/@ValueType = "DATE")'> For some strange reason that doesn't seem to work for me, although similar expressions (without '/@ValueType = "DATE" ' are used around) seem to work there. Please advise. Sorry for the newbie question. Thank you in advance, Oleg. On 3/13/06, andrew welch <andrew.j.welch@xxxxxxxxx> wrote: > On 3/13/06, Oleg Konovalov <olegkon@xxxxxxxxx> wrote: > > Charles/Florent, > > > > Maybe I should explain what I am trying to do > > and show how, so you can comment on whether what I am doing is correct. > > > > I am trying to upload Excel[2000/2003] file, process that info and put > > it in database. > > One of the very important fields is a Start_Date. > > It supposed to be of type "Date" and be in the format mm/dd/yyyy. > > > > If that was not a case (and invalid date format results in making type non-Date, > > that seems to be some Microsoft trick in Excel), > > up until recently we were just putting a fake date like 01/01/2000, > > but that had negative consequences, so now if the type of Start_Date > > is not a Date, > > we are supposed to instead insert that row into Error table (without > > the Start_Date). > > > > So here is my code: > > <xsl:template name='buildStatement'> > > <xsl:param name='row'/> > > <xsl:param name='table'/> > > <xsl:param name='notes'/> > > > > <sql:execute-query> > > <sql:query> > > <xsl:text>insert into </xsl:text> > > <xsl:value-of select='$table'/> > > <xsl:text> (</xsl:text> > > <xsl:for-each select='$row/sht:Cell'> <!--OK: MBR-233 don't insert > > Start_Date if not Date type - PUT condition here too? --> > > Hi, > > This is quite a common problem, you need to invert your processing > here and move all of the conditions to the outside. > > eg, first process all rows with bad start dates, then process all the > good rows:: > > <xsl:for-each select="// all rows with bad start dates"> > ...do something... > </xsl:for-each> > > <xsl:for-each select="// all rows with good start dates"> > ...do something... > </xsl:for-each> > > Where you have code duplication separate it out into named templates. > > It seems backwards at first because you're thinking procedurally, but > when you understand at what point things get added to the result tree > you realise where the conditionals need to be. > > In this the case, a different $table is needed so the conditional must > be at the point that is decided... > > cheers > andrew
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format