[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
cknell@xxxxxxxxxx wrote:
If you're using Xalan and Java, you can always use the (non-standard) extensions.
Something along the following lines (not tested):
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="http://xml.apache.org/xalan/java"
exclude-result-prefixes="java">
...
<xsl:variable name="today">20060517</xsl:variable>
<xsl:variable name="sdf" select="java:java.text.SimpleDateFormat.new('yyyymmdd')" />
<xsl:variable name="tMinus1" select="java:format($sdf, (1000*60*60*24)+java:Long(java:parse($sdf, $today)))" />
...
</xsl:stylesheet>
Re: [xsl] XSLT 2.0/XPath 2.0 Date arithmetic
Subject: Re: [xsl] XSLT 2.0/XPath 2.0 Date arithmetic From: Andrew Franz <afranz0@xxxxxxxxxxxxxxxx> Date: Thu, 18 May 2006 22:50:45 +1000 |
cknell@xxxxxxxxxx wrote:
Given a parameter, let's call it "today" in the form of this string "20060517", how do I create a variable, let's call it "tMinus1" such that it represents a day earlier than "20060517", that would be "20060516". So long as "$today" isn't the first day of a month, a simple subtraction and followed by a type cast that I don't grasp would do the trick.
What I'm looking for is guidance on date arithmetic.
Thanks.
If you're using Xalan and Java, you can always use the (non-standard) extensions.
Something along the following lines (not tested):
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="http://xml.apache.org/xalan/java"
exclude-result-prefixes="java">
...
<xsl:variable name="today">20060517</xsl:variable>
<xsl:variable name="sdf" select="java:java.text.SimpleDateFormat.new('yyyymmdd')" />
<xsl:variable name="tMinus1" select="java:format($sdf, (1000*60*60*24)+java:Long(java:parse($sdf, $today)))" />
...
</xsl:stylesheet>
See http://xml.apache.org/xalan-j/extensions.html#ext-func-calls JavaScript is also available/possible
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XSLT 2.0/XPath 2.0 Date a, Michael Kay | Thread | RE: Re: [xsl] XSLT 2.0/XPath 2.0 Da, cknell |
[xsl] counting elements with values, Sean Whalen | Date | Re: [xsl] counting elements with va, David Carlisle |
Month |