Convert 31-DEC-2016 to 2016-12-31

后端 未结 2 1035
终归单人心
终归单人心 2020-12-22 06:47

I want to convert the 31-DEC-2016 i.e., dd-mmm-yyyy to yyyy-mm-dd in the XSLT using format-dateTime function but the output is not as expected.Can anyone help on this?

2条回答
  •  北海茫月
    2020-12-22 07:00

    You cannot use the format-dateTime() function on a string that is not a valid dateTime (or the format-date() function on a string that is not a valid date). You need to process the string using string functions first.

    Try:

    
        
    
        
        
        
        
    
        
        
        
    
    

    Calling this template with a datestring parameter of "31-DEC-2016" will return a value of "2016-12-31".


    Example of call (mostly guessing, not having seen the input):

    
        
            
        
    
    


    In XSLT 2.0, you can define a function instead of a named template. The following stylesheet:

    XSLT 2.0

    
    
    
    
    
        
        
        
        
    
    
    
        
            
        
    
    
    
    

    will return:

    
    2016-03-09
    

提交回复
热议问题