on 03-30-2011 7:32 PM
Hello Experts,
My requirement is to add one day to current timestamp. Used $TimeSent to get the currenttimestamp. In Expired field, the need to add one day
say Created= 2011-03-30T20:29:13Z
Expired = 2011-03-31T20:29:13Z
<xsl:param name="TimeSent"/>
<created><xsl:value-of select="$TimeSent"/></created>
<expired>2011-03-31T20:29:13Z</expired>
How to add one day to the current timestamp. I am new to XSLT mapping and need some help with the code.
Thanks
Shikha Jain
Edited by: Jain Shikha on Mar 30, 2011 8:34 PM
Edited by: Jain Shikha on Mar 30, 2011 8:36 PM
Try this logic ... This is XSLT 2.0 syntax .
<xsl:function name="functx:next-day" as="xs:date?" xmlns:functx="http://www.functx.com">
<xsl:param name="TimeSent" as="xs:anyAtomicType?"/>
<created>
<xsl:value-of select="$TimeSent"/>
</created>
<expired>
<xsl:sequence select="xs:date($TimeSent) + xs:dayTimeDuration('P1D') "/>
</expired>
</xsl:function>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello All,
Thanks for your reply. i tried the function and the code is working when i am testing in stylus studio. But the same code gives error when i tested the xslt mapping in PI (Error: TransformerConfigurationException triggered while loading XSLT mapping).
$TimeSent function is working when code is tested in PI , but it doesnot give value in stylus studio. Also Current-dateTime() function is doesnot give value in PI but works in stylus studio. Is there any difference in the functions used in stylus studio and XSLT mapping in PI?
Also if i remove the code used for function(to add one day to timestamp), and use constant value(2011-04-02T23:24:56.763Z)the code is working fine in PI. Please help me to find out where the code is going wrong when tested in PI.
Below is the XSLT code i am using
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ds="http://xsltsl.org/date-time" xmlns:functx="http://www.functx.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:function name="functx:next-day" as="xs:date?">
<xsl:param name="TimeSent" as="xs:anyAtomicType?"/>
<xsl:sequence select="xs:date(current-date()) + xs:dayTimeDuration('P1D') "/>
</xsl:function>
<xsl:template match="/">
<xsl:param name="TimeSent"/>
<soapenv:Envelope xmlns:olsa="http://www.skillsoft.com/services/olsa_v1_0/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp wsu:Id="Timestamp-191900" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>
<xsl:value-of select="$TimeSent"/>
</wsu:Created>
<wsu:Expires>
<xsl:value-of select="concat(substring(functx:next-day($TimeSent) ,1,10) ,'T', current-time())"/> </wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken wsu:Id="UsernameToken-19030197" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>ABC</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">XYZ</wsse:Password>
<wsse:Nonce>erDTBNoUWv7GdHDaErrLwA==</wsse:Nonce>
<wsu:Created>2011-02-15T23:24:56.763Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<olsa:GetMultiActionSignOnUrlRequest>
<olsa:customerId>ABC</olsa:customerId>
<olsa:userName>XYZ</olsa:userName>
<olsa:actionType>launch</olsa:actionType>
<olsa:assetId>222499_eng</olsa:assetId>
<olsa:groupCode>testgrp</olsa:groupCode>
</olsa:GetMultiActionSignOnUrlRequest>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
</xsl:stylesheet>
Thanks
Shikha Jain
Edited by: Jain Shikha on Apr 2, 2011 9:51 PM
Hi All,
Thanks for the reply.
Are there any functions available in XSLT 1.0 or XSLT using java extension to achieve the same functionality(Next day timestamp) .Please provide some code samples ,examples or links to achieve the same as i am new to XSLT.
The code used is given in the above post. The code is adding header to the soap message and the current timestamp and next day timestamp is used in the header to get the current and expired time.
Thanks
Shikha Jain
Edited by: Jain Shikha on Apr 5, 2011 9:59 PM
if you want to use XSLT java extension the you might have to create XSL and java in a package and need to import as archive in PI.
sample java code.....
import java.sql.Timestamp;
import java.util.Date;
public class DateTest {
Date now = new Date();
public Date currentDate(){
return now;
}
public Timestamp addOneDateToCurrent(){
now.setDate(now.getDate()+1);
return new Timestamp(now.getTime());
}
public static void main(String args[]){
new DateTest().addOneDateToCurrent();
}
}
In XSL...
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:fruit = "java" > <!-- only the java prefix is declared, the class must be in the current directory -->
<xsl:template match="/">
<xsl:variable name="TimeSent" select="date:DateTest.currentDate()" />
<test>
<instanceMethod><xsl:value-of select="date:DateTest.addOneDateToCurrent($TimeSent)"/></instanceMethod>
</test>
</xsl:template>
</xsl:stylesheet>
Note: You might have to tweak the code. I did not try similar situation before...
Use xslt next day function:
functx:next-day(<DATE>)
Also have a look at the all date and time xslt functions list from below website
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.