Transform 20050416 to 2005-04-16

Discussion in 'XML' started by J-M Andersson, Apr 16, 2005.

  1. How can I transform.
    <date>20050416</date>
    to
    <date>2005-04-16</date>


    Today I do like this (but I guess there should be some better ways)

    <xslt:template match="date">
    <xslt:copy>
    <xslt:value-of select="substring(.,1,4)"/>-
    <xslt:value-of select="substring(.,5,2)"/>-
    <xslt:value-of select="substring(.,7)"/>
    </xslt:copy>
    </xslt:template>
     
    J-M Andersson, Apr 16, 2005
    #1
    1. Advertising

  2. J-M Andersson

    Keith Davies Guest

    J-M Andersson <> wrote:
    > How can I transform.
    ><date>20050416</date>
    > to
    ><date>2005-04-16</date>
    >
    >
    > Today I do like this (but I guess there should be some better ways)
    >
    ><xslt:template match="date">
    > <xslt:copy>
    > <xslt:value-of select="substring(.,1,4)"/>-
    > <xslt:value-of select="substring(.,5,2)"/>-
    > <xslt:value-of select="substring(.,7)"/>
    > </xslt:copy>
    ></xslt:template>


    <xsl:template match='date'>
    <xsl:copy>
    <xsl:value-of select='concat(substring(.,1,4),"-",
    substring(.,5,2),"-",
    substring(.,7,2))' />
    </xsl:copy>
    </xsl:template>

    Not a *lot* better, mind. A little. XSLT is limited in its string-
    processing capabilities.


    Keith
    --
    Keith Davies "Trying to sway him from his current kook-
    rant with facts is like trying to create
    a vacuum in a room by pushing the air
    http://www.kjdavies.org/ out with your hands." -- Matt Frisch
     
    Keith Davies, Apr 16, 2005
    #2
    1. Advertising

  3. Keith Davies wrote:

    >
    >
    > <xsl:template match='date'>
    > <xsl:copy>
    > <xsl:value-of select='concat(substring(.,1,4),"-",
    > substring(.,5,2),"-",
    > substring(.,7,2))' />
    > </xsl:copy>
    > </xsl:template>
    >
    > Not a *lot* better, mind. A little. XSLT is limited in its string-
    > processing capabilities.


    Looks good to me, thanks for the hint.

    /JM
     
    J-M Andersson, Apr 16, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Philippe Geril
    Replies:
    0
    Views:
    1,546
    Philippe Geril
    Nov 19, 2004
  2. Replies:
    0
    Views:
    504
  3. ad
    Replies:
    5
    Views:
    1,622
  4. Juan T. Llibre
    Replies:
    0
    Views:
    493
    Juan T. Llibre
    Jun 7, 2005
  5. =?Utf-8?B?Sm9obiBCYWlsZXk=?=

    Posting VS 2005 RC code to VS 2005 Beta 2 site

    =?Utf-8?B?Sm9obiBCYWlsZXk=?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    415
    =?Utf-8?B?Sm9obiBCYWlsZXk=?=
    Oct 5, 2005
Loading...

Share This Page