[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] expression syntax


Subject: RE: [xsl] expression syntax
From: George James <GeorgeJ@xxxxxxxxxxxxxxx>
Date: Mon, 15 Nov 2004 11:45:23 -0000

Alan
In my suggested solution I'd assumed that date was an attribute of
performance.  That is, you xml would look like this:

	<performance date="2004-11-15">...</performance>

Hence I suggested using @date rather than date in the translate expression.

However, re-reading your original message I see that you had
performance[date = $today] which implies that your xml looks like this:

	<performance><date>2004-11-15</date></performance>

Given that that is how your xml actually looks then this is what I should
have written:

	<xsl:for-each select='performance[translate(date,"-","") &gt;=
$iToday]'/>

David's solution suggested using the number function around the translate
function to cast the string as a date.  For IE6 I found that this wasn't
necessary, but I don't know whether XPath is supposed to automatically cast
a string as a number when doing numeric comparisons, or whether this is an
example of Microsoft's "embrace and extend" policy towards standards.  Does
anyone know the rules here?

Regards
George

George James Software
Cachi Tools, Training, Technology
www.georgejames.com
+44-1932-252568





> -----Original Message-----
> From: Alan Divorty [mailto:alan.divorty@xxxxxxxxxxxxxx]
> Sent: 14 November 2004 21:16
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] expression syntax
>
>
> Thanks guys (incl.George James), but it just keeps failing
> when I try to include the translate in the Select expression.
>
> It was fine translating the input parameter into a new
> variable (as suggested by George) and now I've cheated by
> re-speccing the xml file to have dates without dashes, so it
> now works as required.
>
> Alan
>
> ----- Original Message -----
> From: "M. David Peterson" <m.david@xxxxxxxxxx>
> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Sent: Sunday, November 14, 2004 11:16 AM
> Subject: Re: [xsl] expression syntax
>
>
> > Hey Alan,
> >
> > The two things to consider when using a XSLT 1.0 processor
> (MSXML3 or
> > MSXML4 -- both are possibilities as far as what version of
> MSXML is on
> > your system  -- are XSLT 1.0 processors):
> >
> > - There is no date comparison function.
> > - In 1.0 there is type support for the 4 XPath data types - string,
> > number, boolean, node-set.
> >
> > With this in mind your element date value of 2004-11-14 is
> viewed as a
> > string, not a number.  So using &lt; = or > will return no possible
> > matches for anything that is not a number.  In your case, given the
> > order of your date entities you are in luck as you can
> simply use the
> > translate() function to convert the '-' (dash) to '' (empty
> string or
> > empty space, however you want to term it.  translate(date, '-', '')
> > will accomplish this task.  This will then allow a simple type
> > conversion from a string to a number by using the number
> funtion.  The
> > simplest way to do this is to wrap the previous translate function
> > inside the number function as so:  number(translate(date, '-', ''))
> >
> > To get the results you are looking for my suggestion would
> be to take
> > the above conversion functions and use them within
> > xsl:apply-templates, using the match attribute of a xsl:template
> > element to match the 'date' element and make a copy of that
> particular
> > nodes contents.  So something like this:
> >
> > <xsl:param name="date" select="'20041114'"/>
> > <!-- NOTE: by using param instead of variable you allow
> yourself the
> > ability to pass the value in from outside the template -->
> >
> > <xsl:template match="/">
> >     <dates>
> >         <xsl:apply-templates
> > select="performance/date[number(translate(., '-', ''))
> &gt;= $today]"/>
> >     </dates>
> > </xsl:template>
> >
> > <xsl:template match="date">
> >     <xsl:copy-of select="."/>
> > </xsl:template>
> >
> > Should be much more effective for you in gaining access to
> the nodes
> > that match your number based comparison.  NOTE: Something
> to keep in
> > mind...  The translate function above will only make a copy of the
> > string contained within the date element and use that for
> comparison.
> > The actual value will retain its original '-' delimited string
> > version. The matching template will make a copy of each matching
> > element from the specified criteria (complete copy of the
> element, its
> > attributes (if any), and its value).  So don't be surprised
> to see the
> > dashes still in place when looking at your output.
> >
> > Hope this helps!
> >
> > <M:D/>
> >
> > Alan Divorty wrote:
> >
> > >I am trying to compare two dates, one in the xml data against an
> > >external parameter holding today's date.
> > >
> > >The format of each is yyyy-mm-dd
> > >
> > ><xsl:for-each select="performance[date = $today]">
> > >
> > >successfully processes records with today's date.
> However, I want to
> select
> > >all records equal to or later than today, but
> > >
> > ><xsl:for-each select="performance[date &gt;= $today]">  does not
> > >select
> any
> > >records.
> > >
> > >Is my syntax wrong?
> > >
> > >I'm using IE6 to process the files.
> > >
> > >Thanks,
> > >Alan


Current Thread
Keywords