[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: String manipulation question

Subject: RE: String manipulation question
From: Jarno.Elovirta@xxxxxxxxx
Date: Fri, 19 Jul 2002 15:54:21 +0300
recursive string manipulation
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.