Search code examples
xpathxslt-2.0altova

How to format dd/mm/yy to dd-mon-yyyy in altova stylevision


I am new to Altova Stylevision. I need to format the date from dd/mm/yy to dd/Mon/yyyy.

I have tried the options suggested in the Altova manual but it does not seem to recognize the format.


Solution

  • This question is almost three weeks old, so maybe meanwhile you have found an answer, for instance by looking it up at page 781 of XSLT 2.0 and XPath 2.0 Programmer's Reference by Michael Kay. Or perhaps somewhere else on the web.

    To achieve what you want in XSLT 2.0, we first need to convert your date-like string into international date-time notation. Luckily, we only need to care about the date-part, which should take the form YYYY-MM-DD.

    After that, we "just" need to call format-date with the proper picture string:

    <!-- first, convert your date into int'l date-notation with a regex -->
    <xsl:variable 
        name="date" 
        select="replace('14/09/2014', '(\d+)/(\d+)/(\d+)', '$3-$2-$1')" />
    
    <!-- then, use a properly formatted picture string to get the abbrev. month -->
    <xsl:value-of 
        select="format-date(xs:date($date), '[D01]/[MNn,3-3]/[Y]')" />
    

    The output with conforming processors like Saxon or Exselt (didn't try Altova) is this: 14/Sep/2014.

    The picture string works as follows (from that same book I quoted):

    • [xxxx] is a variable marker
    • [D01] formats the day-part as a two-digit day (leave out the zero if you don't want leading zeroes)
    • [MNn,3-3] formats the month with M as case-word with Nn with a width of min three and max three with 3-3.
    • [Y] formats the year in the default format as a four-digit year.

    If you need the full name of the month, remove the width-specifier. If you need some other output, check out the table in the XPath 3.0 specification for what you can use in the picture string.