This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: String manipulation question
- From: Bodrul Haque <Bodrul dot Haque at Synergy-Logistics dot co dot uk>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 19 Jul 2002 16:15:25 +0100
- Subject: RE: [xsl] String manipulation question
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Jenni, Santtu, Antonio,
Thanks for the tips. It definitely helps. Its always great to get the ideas
of coding gurus.
Cheers
BTW Santtu,
That's one heavy duty select statement you got there........especially for a
friday. Great solution. Its a lot shorter(and neater) than anything I
thought of.
Regards
Bodrul
-----Original Message-----
From: Jarno.Elovirta@nokia.com [mailto:Jarno.Elovirta@nokia.com]
Sent: 19 July 2002 13:54
To: xsl-list@lists.mulberrytech.com
Subject: RE: [xsl] String manipulation question
Hi,
> My question is regarding some string manipulation.
> I have template which looks at a string value of a date
> (eg 02-03-02 param1) and a dateformat (eg. DD-MM-YY param2).
>
> My template has to (for e.g.):
> return 02-03-02
> if param1= 2-3-02
> and param2= DD-MM-YY
>
> or
> return 02/03/2002
> if param1= 02/3/02
> and param2= DD-MM-YYYY
>
>
> I'm having difficulties in thinking of a short and neat way
> of appending '0'
> in front of any number between 1-9 (if its not already there).
> [And appending a '20' for a year format (if its not already there)].
> Any help appreciated.
It's friday, so...
<xsl:template name="dateFormat">
<xsl:param name="str" />
<xsl:param name="date-format" />
<xsl:choose>
<xsl:when test="contains($str, '-')">
<xsl:value-of select="concat(format-number(substring-before($str,
'-'), substring(substring('2000', 4 -
string-length(substring-before($date-format, '-'))), 1,
string-length(substring-before($date-format, '-')))), '-')"/>
<xsl:call-template name="dateFormat">
<xsl:with-param name="str" select="substring-after($str, '-')" />
<xsl:with-param name="date-format"
select="substring-after($date-format, '-')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number($str, substring(substring('2000',
4 - string-length($date-format)), 1, string-length($date-format)))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
I'll also format YYYY-MM-DD.
Cheers,
Santtu
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
---------------------------------------------------------------------------
The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material.
Any views or opinions presented in this Email message are solely those
of the author and do not necessarily represent those of Synergy
Logistics Limited unless specifically stated.
Email communications are not necessarily secure and therefore
Synergy Logistics Limited does not accept legal responsibility for the
contents of this message.
If you are not the intended recipient and have received this message in
error, Please notify Synergy Logistics Limited immediately.
Synergy Logistics Ltd. 01509 232706
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list