Created
October 19, 2012 23:52
-
-
Save gjbroom/9a1f296a743030796987 to your computer and use it in GitHub Desktop.
XSL to transform Unity Pro date stamps in .XEF file to ISO8601 format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Fun fun! Parse Unity Pro date stamp and normalize to ISO8601. Add leading zeros to fields if they aren't there. --> | |
<xsl:variable name="fullTs"><xsl:value-of select="substring-after(/FEFExchangeFile/fileHeader/@dateTime, 'date_and_time#')"/></xsl:variable> | |
<xsl:variable name="year"><xsl:value-of select="substring-before($fullTs, '-')" /></xsl:variable> | |
<xsl:variable name="month"><xsl:value-of select="substring-before(substring-after($fullTs, '-'), '-')"></xsl:value-of></xsl:variable> | |
<xsl:variable name="day"><xsl:value-of select="substring-before(substring-after(substring-after($fullTs, '-'), '-'), '-')"/></xsl:variable> | |
<xsl:variable name="hour"><xsl:value-of select="substring-before(substring-after(substring-after(substring-after($fullTs, '-'), '-'), '-'), ':')"/></xsl:variable> | |
<xsl:variable name="minute"><xsl:value-of select="substring-before(substring-after(substring-after(substring-after(substring-after($fullTs, '-'), '-'), '-'), ':'), ':')"/></xsl:variable> | |
<xsl:variable name="second"><xsl:value-of select="substring-after(substring-after(substring-after(substring-after(substring-after($fullTs, '-'), '-'), '-'), ':'), ':')"/></xsl:variable> | |
<!-- then use like this... --> | |
<xsl:copy-of select="$year" /><xsl:text>-</xsl:text> | |
<xsl:if test="string-length($month)=1"><xsl:text>0</xsl:text></xsl:if> | |
<xsl:copy-of select="$month" /><xsl:text>-</xsl:text> | |
<xsl:if test="string-length($day)=1"><xsl:text>0</xsl:text></xsl:if> | |
<xsl:copy-of select="$day" /> | |
<xsl:text>T</xsl:text> | |
<xsl:if test="string-length($hour)=1"><xsl:text>0</xsl:text></xsl:if> | |
<xsl:copy-of select="$hour" /><xsl:text>:</xsl:text> | |
<xsl:if test="string-length($minute)=1"><xsl:text>0</xsl:text></xsl:if> | |
<xsl:copy-of select="$minute" /><xsl:text>:</xsl:text> | |
<xsl:if test="string-length($second)=1"><xsl:text>0</xsl:text></xsl:if> | |
<xsl:copy-of select="$second" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is XSLT 1.0, so we have to split using
substring-before
andsubstring-after
instead oftokenize
. Any text being injected is wrapped in an<xst:text>
block so we don't get spurious whitespace.