Subject: Re: [xsl] expression syntax From: "Alan Divorty" <alan.divorty@xxxxxxxxxxxxxx> Date: Sun, 14 Nov 2004 21:15:52 -0000 |
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 < = 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(., '-', '')) >= $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 >= $today]"> does not select any > >records. > > > >Is my syntax wrong? > > > >I'm using IE6 to process the files. > > > >Thanks, > >Alan
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] expression syntax, M. David Peterson | Thread | RE: [xsl] expression syntax, George James |
[xsl] regular expression question, Bruce D'Arcus | Date | Re: [xsl] regular expression questi, M. David Peterson |
Month |