Reputation: 51
I have an xml that looks something like this
<book>
<name>someName</name>
<date>2014-02-05-05:00</date>
</book>
<book>
<name>DifferentName</name>
<date>2014-04-05-05:00</date>
</book>
In my xslt i have this schemas
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
So when i do
<xsl:variable name='myDate' select='date' />
<xsl:value-of select="$myDate" />
it works fine, but when i try to do this
<xsl:variable name='date' select='impactDate' />
<xsl:value-of select="ms:format-date($date, 'MMM dd, yyyy')"/>
I get this exception
The first argument to the non-static Java function 'formatDate' is not a valid object reference.
Does any one know how to fix this exception or is there any other function i can use to do this.
Thank you
Upvotes: 0
Views: 1367
Reputation: 1645
ms:format-date expects a dateTime string that has to be formatted like this: 2000-02-16T15:56:00
try getting it in the correct format first, something like:
<xsl:variable name="date" select="concat(substring(date,1,10),'T',substring(date,12),':00')"/>
<xsl:value-of select="ms:format-date($date, 'MMM dd, yyyy')"/>
Edit: Just saw you're using java for the transformation, for the ms:* functions to work I think you will have to use MSXML or .Net to do your transformation
Upvotes: 0
Reputation: 8058
Note that, as it name suggests, ms:anything is a microsoft-specific extension function and is NOT PORTABLE. Bad practice if you can solve the problem any other way, since you're putting yourself in a position where you'll have to go looking for another solution if you ever change XSLT processors.
Better practice would be to use the EXSLT Date Extensions. EXSLT is still a set of extension functions and therefore is not guaranteed to be implemented in all XSLT processors -- but many do support most or all of these, and they have the huge advantage that if they're supported at all they will work the same way on all processors that support them.
If you look at the EXSLT page, you'll also find that they show XSLT implementations of many of these functions (as named templates), which can be copied into your stylesheet and used as a completely portable solution.
Upvotes: 1