xsl-list
[Top] [All Lists]

Re: Re: [xsl] Complex expression

2006-03-16 07:43:38
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(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com> 
wrote:
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>
--~--



--~------------------------------------------------------------------
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>