XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Mike SappSubject: 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...

Postnext
(Deleted User) Subject: Date Sequence
Author: (Deleted User)
Date: 12 Sep 2007 03:51 AM
Hi Mike,
if you can use XSLT 2.0, you can use substring-after and substring-before to extract the numbers between the "/"; once you have the individual components of the date
- create a new string in the format YYYY-MM-DD
- create a new date by invoking the xs:date function on that string
- create a new duration by invoking xs:yearMonthDuration("P50Y")
- add the date to the duration

Hope this helps,
Alberto

Postnext
Mike SappSubject: 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.

Postnext
(Deleted User) 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

Postnext
Mike SappSubject: 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-

Postnext
(Deleted User) Subject: Date Sequence
Author: (Deleted User)
Date: 25 Sep 2007 08:15 AM
Originally Posted: 25 Sep 2007 08:14 AM
Hi Mike,
the arguments for xs:date must be kept in that order, as it requires that specific layout; you should just use format-date on the resulting date, using a picture of "[D]/[M]/[Y]"

Hope this helps,
Alberto

Postnext
Mike SappSubject: Date Sequence
Author: Mike Sapp
Date: 25 Sep 2007 08:23 AM
Ive never done that before... Im sorry to ask, but can you point me in the right direction?

Posttop
(Deleted User) Subject: Date Sequence
Author: (Deleted User)
Date: 25 Sep 2007 02:40 PM
<xsl:value-of select="format-date(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'), '[D]/[M]/[Y]')"/>

Alberto

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.