Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT template

Reply
Thread Tools

XSLT template

 
 
Mark
Guest
Posts: n/a
 
      07-13-2004
Hello,

I'm having problems with an XSLT template I'm developing.

I have a date in an odd format which I'm trying to convert into something
more readable. The original date is in the format YYYY-MM-DD, and I'd like
to convert it to DD MON YY.

I pass the date into my template thusly in my XSLT stylesheet (date-updated
is the data I'm passing in):

<xsl:call-template name="formatDate">
<xsl:with-param name="string" select="date-updated" />
</xsl:call-template>

.... and the template is thus:

<xsl:template name="formatDate">
<xslaram name="inDate" />
<!-- Day -->
<xsl:variable name="day" select="number(substring($inDate, 9, 2))" />
<!-- Month -->
<xsl:variable name="month" select="number(substring($inDate, 6, 2))" />
<xsl:variable name="converted-month">
<xsl:choose>
<xsl:when test="$month=format-number('01', '00')">
<xsl:value-of select="Jan" />
</xsl:when>
....
<xsl:when test="$month='12'">
<xsl:value-of select="Dec" />
</xsl:when>
</xsl:choose>
</xsl:variable>
<!-- Year -->
<xsl:variable name="year" select="number(substring($inDate, 3, 2))" />
<!-- Formatted Date -->
<xsl:value-of select="concat($inDate, ': ', format-number($day, '00'), '
', $converted-month, ' ', format-number($year, '00'))" />
</xsl:template>

The output I get is:

: NaN NaN

NaN = Not a number, of course, but I can't see why such an error should be
raised.

Thanks for any assistance,

Mark


 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      07-13-2004


Mark wrote:


> <xsl:call-template name="formatDate">
> <xsl:with-param name="string" select="date-updated" />
> </xsl:call-template>
>
> ... and the template is thus:
>
> <xsl:template name="formatDate">
> <xslaram name="inDate" />


I think you need
<xslaram name="string" />
here or
<xsl:with-param name="inDate" select="date-updated" />
above, the name of the parameter needs to be the same in xsl:with-param
and xslaram.


--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
 
 
 
Mark
Guest
Posts: n/a
 
      07-13-2004
> I think you need
> <xslaram name="string" />
> here or
> <xsl:with-param name="inDate" select="date-updated" />
> above, the name of the parameter needs to be the same in xsl:with-param
> and xslaram.


Yes, you're right - thanks.

Mark


 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      07-13-2004
> Yes, you're right - thanks.

Another problem - the month comes in as a 2 digit number (e.g. 01 for Jan).

How can I convert it to the text "Jan"?

I've tried the following:

<xsl:variable name="month" select="number(substring($inDate, 6, 2))"/>
<xsl:variable name="converted-month">
<xsl:choose>
<xsl:when test="$month='1'">
<xsl:value-of select="Jan"/>
</xsl:when>
....
</xsl:choose>
</xsl:variable>

.... but the match is never made: it always produces no output.

I've tried outputting $month, and that produces the correct month number
(e.g. "1", rather than "01"), so the correct data is going in. I just can't
seem to get the comparison right.

Thanks for any information,

Mark


 
Reply With Quote
 
A. Bolmarcich
Guest
Posts: n/a
 
      07-13-2004
In article <40f3e4b9$0$13162$(E-Mail Removed)>, Mark wrote:
> Another problem - the month comes in as a 2 digit number (e.g. 01 for Jan).
>
> How can I convert it to the text "Jan"?
>
> I've tried the following:
>
> <xsl:variable name="month" select="number(substring($inDate, 6, 2))"/>
> <xsl:variable name="converted-month">
> <xsl:choose>
> <xsl:when test="$month='1'">
> <xsl:value-of select="Jan"/>
> </xsl:when>
> ...
> </xsl:choose>
> </xsl:variable>
>
> ... but the match is never made: it always produces no output.


The match is made, but <xsl:value-of select="Jan"/> is the value of the
element named "Jan". Because there is no element named "Jan", the value
is empty. If you want the value to be a string use

<xsl:value-of select="'Jan'"/>

If you want the value to be a text node use

<xsl:text>Jan</xsl:text>
 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      07-14-2004
> The match is made, but <xsl:value-of select="Jan"/> is the value of the
> element named "Jan". Because there is no element named "Jan", the value
> is empty. If you want the value to be a string use
>
> <xsl:value-of select="'Jan'"/>
>
> If you want the value to be a text node use
>
> <xsl:text>Jan</xsl:text>


Great - thank you very much.

Mark


 
Reply With Quote
 
Deirdre Saoirse Moen
Guest
Posts: n/a
 
      07-19-2004
Mark <(E-Mail Removed)> wrote:
> I have a date in an odd format which I'm trying to convert into
> something more readable. The original date is in the format
> YYYY-MM-DD, and I'd like to convert it to DD MON YY.


As an aside, what's so "odd" about the ISO (8601) date format?

http://www.hermetic.ch/cal_stud/formats.htm

--
_Deirdre web: http://deirdre.net blog: http://deirdre.org/blog/
"Memes are a hoax! Pass it on!"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use the template member function of a template in the memberfunction of another template class? Peng Yu C++ 3 10-26-2008 03:51 PM
template template arguments: expected a class template, got `Component<T1, T2, T3> gary.bernstein@gmail.com C++ 1 06-08-2007 07:10 AM
Q: XSLT transforming result of one template with another template- how? Bernd Fuhrmann XML 0 02-12-2004 01:59 PM
Re: A Newbie Question about template template template tom_usenet C++ 0 07-24-2003 12:06 PM
Re: A Newbie Question about template template template Chris Theis C++ 2 07-24-2003 09:42 AM



Advertisments