Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 5th, 2017, 02:46 PM
Authorized User
Points: 340, Level: 6
Points: 340, Level: 6 Points: 340, Level: 6 Points: 340, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: , OH, USA.
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default current-datetime() per execution loop

I understand why current-dateTime returns single value within a single XSLT, but is there any way to work around this in XSLT/XPath 2.0 ?

I have a scenario where I'd like to generate multiple xml documents and I'd like each one to get a "different" timestamp. Any options?

Code:
<xsl:template match="/">
	<xsl:for-each select="row">
		<xsl:variable name="vPROCESSDATE_REPLACE" select="format-dateTime(current-dateTime(),'[Y0001]-[M01]-[D01]T[H]:[m]:[s].[f]')"/>
			<xsl:result-document href="{$outputDir}/{$vCLAIM_NUMBER}.xml">
			<xsl:call-template name="updateXML">
				<!-- Do Stuff -->
			</xsl:call-template>
		</xsl:result-document>
	</xsl:for-each>
</xsl:template>
Reply With Quote
  #2 (permalink)  
Old May 9th, 2017, 07:19 PM
mhkay's Avatar
Wrox Author
Points: 18,274, Level: 58
Points: 18,274, Level: 58 Points: 18,274, Level: 58 Points: 18,274, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,932
Thanks: 0
Thanked 282 Times in 277 Posts
Default

You could use an extension function that gets the actual machine timestamp. But this offers no guarantee of uniqueness because two xsl:result-document instructions might be evaluated simultaneously (the XSLT spec does not prescribe sequential execution, and some processors such as Saxon-EE will execute different instructions in parallel).

Is your proposal to use timestamps as unique identifiers for result documents merely because you think this is the easiest way to get a unique identifier, or is there actually a requirement to reflect the exact time the file was created?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
iceandrews (May 10th, 2017)
  #3 (permalink)  
Old May 10th, 2017, 09:29 AM
Authorized User
Points: 340, Level: 6
Points: 340, Level: 6 Points: 340, Level: 6 Points: 340, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: , OH, USA.
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default

The requirement was that each one have a unique time stamp. I used the java include to get real time time stamps, but as you indicated, I did get duplicates.

I got creative after that. I used the position of each row in the CSV, converted it to a 1 second xs:duration and added to the current-dateTime() with each result document. Worked like a charm!

Code:
<xsl:variable name="vRowDuration" select="xs:duration(concat('PT',$vRowNumber,'.0S'))"/>

<xsl:variable name="vPROCESSDATE_REPLACE"  select="format-dateTime((xs:dateTime(current-dateTime()) + xs:dayTimeDuration($vRowDuration)),'[Y0001]-[M01]-[D01]T[H]:[m]:[s].[f]')"/>
Thanks!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to compare current value with previous value in a loop pallone Javascript How-To 8 July 8th, 2011 06:13 AM
3 days prior datetime from current datetime bsridharg XSLT 2 June 12th, 2010 12:26 AM
How do I compare a datetime to current datetime and find the one closest to it? Anders XSLT 17 March 15th, 2010 11:28 AM
How can I use the current object in a loop as part of a query? pagis XSLT 1 January 7th, 2009 04:05 AM
how to get current-dateTime() in xsl 1.0 himabindu XSLT 3 September 5th, 2008 06:04 AM



All times are GMT -4. The time now is 04:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.