[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Re: Complex expression
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
|