c# - Format a date in XML via XSLT -


When I use XML SerialIser to serial a DateTime The format is written in:

  & lt; Date & gt; 2007-11-14 T12: 01: 00 & lt; / Date & gt;  

When this is going to output HTML through an XSLT stylesheet, how can I format it? In most cases I just need a date, and when I need time, I definitely do not want to "weird t" there. Here are some 1.0 templates you can use: -

 

Code> & lt; Xsl: template name = "formatDate" & gt; & Lt; Xsl: Ultimate Name = "Date Time" /> & Lt; Xsl: variable name = "date" = "sub-first ($ datetime, 't')" /> & Lt; Xsl: variable name = "year" = "sub - before ($ date, '-')" /> & Lt; Xsl: variable name = "month" = "sub-substitute (after substring ($ date, '-'), '-')" /> & Lt; Xsl: variable name = "day" = "after sub-location (sub-location ($ date, '-'), '-')" /> & Lt; Xsl: Select value = "concat ($ day, '', $ month, '', $ year)" /> & Lt; / XSL: Templates & gt; & Lt; Xsl: Template Name = "Format Time" & gt; & Lt; Xsl: Ultimate Name = "Date Time" /> & Lt; Xsl: Select Value = "Substring-After ($ DateTime, 'T')" /> & Lt; / XSL: Templates & gt;

Call them with: -

  & lt; Xsl: call-template name = "format date" & gt; & Lt; With xsl: select param name = "date time" = "xpath" /> & Lt; / XSL: Call-templates & gt;  

and

  & lt; Xsl: call-template name = "format time" & gt; & Lt; With xsl: select param name = "date time" = "xpath" /> & Lt; / XSL: Call-templates & gt;  

Where xpath is the path of an element or feature that has the standard date time format.


Comments