xsl-list
[Top] [All Lists]

Re: Re: [xsl] Complex expression

2006-03-13 06:52:47
On 3/13/06, Oleg Konovalov <olegkon(_at_)gmail(_dot_)com> 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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>