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 6 2838
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/
> 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
> 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
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>
> 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
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!" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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>...
|
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...
|
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...
|
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...
|
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...
|
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" ...
|
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
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |