473,795 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="formatDat e">
<xsl:with-param name="string" select="date-updated" />
</xsl:call-template>

.... and the template is thus:

<xsl:template name="formatDat e">
<xsl:param name="inDate" />
<!-- Day -->
<xsl:variable name="day" select="number( substring($inDa te, 9, 2))" />
<!-- Month -->
<xsl:variable name="month" select="number( substring($inDa te, 6, 2))" />
<xsl:variable name="converted-month">
<xsl:choose>
<xsl:when test="$month=fo rmat-number('01', '00')">
<xsl:value-of select="Jan" />
</xsl:when>
....
<xsl:when test="$month='1 2'">
<xsl:value-of select="Dec" />
</xsl:when>
</xsl:choose>
</xsl:variable>
<!-- Year -->
<xsl:variable name="year" select="number( substring($inDa te, 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 2859


Mark wrote:

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

... and the template is thus:

<xsl:template name="formatDat e">
<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($inDa te, 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************ ***********@new s.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($inDa te, 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.c o.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
2713
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 extension responsible for the xslt functions. The problem i have is that the obtained transformation is not the waited one. I try to proccess the same XML file with XSL file with a program called XMLspy and i obtained the desire and waited...
2
3906
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 "crumb-trail" of links. I'm transforming the XML with XSLT through Saxon. The nav menu and "crumb-trail" show the user where they are within the site and is made by reflecting the XML tree structure. My problem now is that when I want to generate...
8
2165
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 id="1"> <balance>100</balance>
7
2871
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 parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID); xmlItems.TransformArgumentList = xsltArgList;
2
1868
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> <o><n>3</n><si>s</si><v1>7</v1><v2>8</v2><v3>9</v3></o> <o><n>5</n><si>i</si><v1>10</v1><v2>11</v2><v3>12</v3></o> <o><n>6</n><si>i</si><v1>13</v1><v2>14</v2><v3>15</v3></o> </r>
12
2922
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 the file. Here is the code snippet: XPathDocument xdoc = new XPathDocument(fs); XPathNavigator nav = xdoc.CreateNavigator(); xslt.Transform(nav, null, strWriter, null);
18
2089
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 look up what each feature depends on and gerenate a text file. For example, in the following file, I would like to find out feature A depends on A1 and A2 and feature B depends on B1 and B2. And write that to a text file.
8
15904
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 case that i don't know how to solve, I need to concat a string from multiple childs into a standard way, the following is an example of the source and the target XML.
2
22780
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 in the attribute of an element. Instead of using the <xsl:attribute> element, you can simply place the xpath in the attribute itself. The most common usage of this is in creating hyperlinks.
1
5712
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" project="neptune"/> <file name="potrzebie.dbf" size="1102" project="jupiter"/>
0
10443
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10216
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9044
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.