1

I want to subtract 1 day to the current date. Need solution in XSLT 2.0

I have tried the Current Date() and it is getting reflected in the XSLT.

Regards Zulfikarlos

2 Answers 2

3

Use current-date() - xs:dayTimeDuration('P1D')

5
  • Then tell us exactly what you did and exactly how it failed. Jun 3, 2015 at 22:46
  • What is the purpose of "xs:", cause when i had ran i am getting error, which is as follows..... [9.1.0.3] Starting transformation ... FATAL ERROR: XPath syntax error at char 42 on line 40 in {...() - xs:dayTimeDuration('P1...}: Undeclared namespace prefix {xs}; SystemID: file:/C:/Users/WELCOME/Desktop/31384_XSLT_Activity.xsl; Line#: 40; Column#: 85 FATAL ERROR: Failed to compile stylesheet. 1 error detected. Transformation Interrupted! Jun 3, 2015 at 22:49
  • The namespace prefix "xs" is conventionally used for all references to XSD-defined types. You need to include xmlns:xs="http://www.w3.org/2001/XMLSchema" in your stylesheet, typically on the xsl:stylesheet element. It's often useful to add exclude-result-prefixes="xs" as well. Jun 3, 2015 at 22:51
  • After adding the said XSD-defined type, there is the same error. which is as follows..... [9.1.0.3] Starting transformation ... FATAL ERROR: XPath syntax error at char 42 on line 40 in {...() - ws:dayTimeDuration('P1...}: Undeclared namespace prefix {ws}; SystemID: file:/C:/Users/WELCOME/Desktop/31384_XSLT_Activity.xsl; Line#: 40; Column#: 85 FATAL ERROR: Failed to compile stylesheet. 1 error detected. Transformation Interrupted! Jun 3, 2015 at 22:56
  • 1
    @zulfikarlos: Edit your question to show us a minimal but complete example that produces the error to help us "help!!!!!!" you. Know that Michael's answer is correct and that you're likely making a simple mistake in applying it. Thanks.
    – kjhughes
    Jun 4, 2015 at 0:45
0

Finally got an answer, thanks all for the help

"current-date() -7*xs:dayTimeDuration('P1D')"

xmlns:xs="http://www.w3.org/2001/XMLSchema" (Need to be added in your stylesheet.

7 days is the number of days that i wanted to subtract from current day.

Regards, Zulfikarlos

3
  • "7 days is the number of days that i wanted to subtract from current day." Well, in your question you say that "I want to subtract 1 day to the current date." -- If you want to subtract 7 days, you should use current-date() - xs:dayTimeDuration('P7D'). Jun 4, 2015 at 7:22
  • @michael.hor257k It's for people like this that we write optimizers. Jun 4, 2015 at 8:12
  • Well, for a functional guys like me this is very complex to understand, it is not like an expert in XSLT, i am just copy pasting the codes that you people have designed or developed, hence please excuse my blunder in understanding the XSLT Language. With regards to current-date() - xs:dayTimeDuration('P7D'), yes 7 days was my requirement but that the code dint work with 1 days as an requirement too. Please excuse me if i have not understood the XSLT language, i have only stared working in XSLT since yesterday, hence request answers with detail explanation. Jun 4, 2015 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.