I have searched google and Here for an answer. I am trying to use a date formatting function. I am new to XML but I like to research prior to asking. This is for a MS project f
If you want to use XSLT 2.0 date formatting functions client-side, consider using Saxon-JS. The XSLT processors available natively from the browser vendors have been moribund for about 15 years.
A couple of other little things to help you on your XSLT learning curve:
(a) Your variable declaration would be better written <xsl:variable name="mdate" select="Start"/>
- binding a variable to an element (or sequence of elements) is a much simpler operation than creating a new node tree (or result tree fragment) and copying the data from the source document.
(b) If you do decide to use an XSLT 2.0/3.0 processor, the input to format-date()
must be an xs:date
, whereas your value looks like an xs:dateTime
.
I know it's old-fashioned but learning the concepts of a new language through google is really hard work; when you're starting it's very hard to distinguish quality information from dross, and when you find quality information you may not understand it because it assumes more knowledge than you have at this stage of the learning curve. In my view, since you say you like to research things, there's really no substitute for a good book.
To convert a ISO-8601 dateTime to a date in MM-DD-YYYY format using XSLT 1.0, you can do:
<xsl:value-of select="substring($mdate, 6, 2)"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="substring($mdate, 9, 2)"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="substring($mdate, 1, 4)"/>