Subject: Re: [xsl] expression syntax From: "M. David Peterson" <m.david@xxxxxxxxxx> Date: Mon, 15 Nov 2004 04:32:44 -0800 |
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,"-","") >= $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,(MSXML3 or
The two things to consider when using a XSLT 1.0 processor
MSXML4 -- both are possibilities as far as what version ofMSXML is on
your system -- are XSLT 1.0 processors):viewed as a
- 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
string, not a number. So using < = 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 cansimply use the
translate() function to convert the '-' (dash) to '' (emptystring 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 numberfuntion. The
simplest way to do this is to wrap the previous translate function inside the number function as so: number(translate(date, '-', ''))be to take
To get the results you are looking for my suggestion would
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 thatparticular
nodes contents. So something like this:yourself the
<xsl:param name="date" select="'20041114'"/>
<!-- NOTE: by using param instead of variable you allow
ability to pass the value in from outside the template -->>= $today]"/>
<xsl:template match="/">
<dates>
<xsl:apply-templates select="performance/date[number(translate(., '-', ''))
the nodes</dates> </xsl:template>
<xsl:template match="date"> <xsl:copy-of select="."/> </xsl:template>
Should be much more effective for you in gaining access to
that match your number based comparison. NOTE: Somethingto keep in
mind... The translate function above will only make a copy of the string contained within the date element and use that forcomparison.
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 theelement, its
attributes (if any), and its value). So don't be surprisedto see the
dashes still in place when looking at your output.However, I want to
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.
select
anyall records equal to or later than today, but
<xsl:for-each select="performance[date >= $today]"> does not select
records.
Is my syntax wrong?
I'm using IE6 to process the files.
Thanks, Alan
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] expression syntax, David Carlisle | Thread | Re: [xsl] expression syntax, G. Ken Holman |
[xsl] Translating "(", Huditsch Roman | Date | Re: [xsl] Translating "(", David Carlisle |
Month |