473,383 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

XSLT template

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">
<xsl:param 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
Jul 20 '05 #1
6 2836


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">
<xsl:param name="inDate" />


I think you need
<xsl:param 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 xsl:param.
--

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

Jul 20 '05 #2
> I think you need
<xsl:param 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 xsl:param.


Yes, you're right - thanks.

Mark
Jul 20 '05 #3
> 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
Jul 20 '05 #4
In article <40***********************@news.easynet.co.uk>, 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>
Jul 20 '05 #5
> 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
Jul 20 '05 #6
Mark <ma****************@ukonline.co.uk.nospam> 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!"
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
2
by: ted | last post by:
Was wondering if XSLT alone is appropriate for the following situation. From XML, I'm creating a small website (around 50 pages) with pages that link to each other through a nav menu and a...
8
by: Maciej Wegorkiewicz | last post by:
Hi, I have small experience in XSLT processing and I have a problem which I cannot solve. Can you look at it? I have an input file containing info about bank accounts like this: (...) <acc...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
2
by: Michael Hamm | last post by:
I have the following XML file (simplified from the actual): <r> <o><n>1</n><si>s</si><v1>1</v1><v2>2</v2><v3>3</v3></o> <o><n>2</n><si>i</si><v1>4</v1><v2>5</v2><v3>6</v3></o>...
12
by: das | last post by:
Hello all, I am using .NET XSLT to transform an XML into another XML file. All this is fine with small files, but when tested with big files (30MB) it is taking between 1hr-2hrs to just transform...
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
8
by: Hercules Dev. | last post by:
Hi all, I'm new in xslt and xpath, so my question might be simple but i'm learning. I have an XML document and need to transform it into another XML, I use xslt and it works, but there is a...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
1
by: Sandeep Singh | last post by:
Hi, How to do group by in XSLT ? I tried on the following codes: <files> <file name="swablr.eps" size="4313" project="mars"/> <file name="batboy.wks" size="424" ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.