|
next
|
Subject: Date Sequence Author: Mike Sapp Date: 11 Sep 2007 11:27 PM Originally Posted: 11 Sep 2007 11:26 PM
|
Hello,
Im fairly new to XML and im stuck with trying to re-order and process a date. The XML looks like this:
<PhysicalReleaseDate>8/21/2007</PhysicalReleaseDate>
It is obviously mm/dd/yyyy. Im trying to get the ReleaseDate to translate to dd/mm/yyyy. Also, i cant do just a simple substring-after(PhysicalReleaseDate,1,2) as there is a chance that the days may be only a single digit instead of double digits (ie 9 instead of 09)
The XSL i have so far looks like this, but im having troubles with it. Any pointers on how i can get the day from between the '/' marks as well as the year?
<AlbumReleaseDate>
<xsl:value-of select="concat(substring(substring-after(PhysicalReleaseDate,'/'),1,2),substring-before(PhysicalReleaseDate,'/'),'/')"/>
</AlbumReleaseDate>
<AlbumCancellationDate>
</AlbumCancellationDate>
Additionally, i have to create an output of +50 years for the <AlbumCancellationDate> and im not sure how to do this...
|
next
|
Subject: Date Sequence Author: Mike Sapp Date: 12 Sep 2007 09:06 AM Originally Posted: 12 Sep 2007 06:27 AM
|
Hi Alberto,
Thank you for your help, but i think that the main problem is that i have never used the xs:date function.
I succeeded using your advice of substring after & before however have not been able to add 50 years to the end date.
<xsl:value-of select="concat(substring-before(substring-after(PhysicalReleaseDate,'/'),'/'),'/',substring-before(PhysicalReleaseDate,'/'),'/', substring-after(substring-after(PhysicalReleaseDate,'/'),'/'))"/>
The current result is 1/9/2007 (Sept 1st, 2007) and would like to get an output of Sept 1st, 2057.
|
next
|
Subject: Date Sequence Author: (Deleted User) Date: 12 Sep 2007 02:22 PM
|
Hi Mike,
here is a little XSLT 2.0 that does everything you need:
<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="iDate" select="'9/1/2007'"/>
<xsl:variable name="iYear" select="substring-after(substring-after($iDate,'/'),'/')"/>
<xsl:variable name="iMonth" select="substring-before($iDate,'/')"/>
<xsl:variable name="iDay" select="substring-before(substring-after($iDate,'/'),'/')"/>
<xsl:value-of select="xs:date(concat(
$iYear,'-',
if(string-length($iMonth)=1) then concat('0',$iMonth) else $iMonth,'-',
if(string-length($iMonth)=1) then concat('0',$iDay) else $iDay))
+xs:yearMonthDuration('P50Y')"/>
</xsl:template>
</xsl:stylesheet>
Hope this helps,
Alberto
|
next
|
Subject: Date Sequence Author: Mike Sapp Date: 24 Sep 2007 05:03 AM Originally Posted: 22 Sep 2007 06:47 AM
|
I need to change the format to dd/mm/yyyy (and then add 50 years to the yyyy) and for some reason
i get an error stating 'When year exceeds 4 digits, leading zeroes not allowed'. The original date for PhysicalReleaseDate is 9/1/2007
Here is the ordering that i did to try to get dd/mm/yyyy (+50 years)
<xsl:variable name="iDate" select="PhysicalReleaseDate"/>
<xsl:variable name="iYear" select="substring-after(substring-after($iDate,'/'),'/')"/>
<xsl:variable name="iMonth" select="substring-before($iDate,'/')"/>
<xsl:variable name="iDay" select="substring-before(substring-after($iDate,'/'),'/')"/>
<xsl:value-of select="xs:date(concat(if(string-length($iDay)=1) then concat('0',$iDay) else $iDay,
'/',
if(string-length($iMonth)=1) then concat('0',$iMonth) else $iMonth,
'/',
$iYear
))
+xs:yearMonthDuration('P50Y')"/>
Any idea as to how to work around this error would be greatly appreciated-
|
|
|
|