Convert datetime fields using XSLT Formats
I'm trying to convert a timestamp (from a datetime Data
Definition field) into readable dates. I tried using the Xalan
component suggested in this post:
http://success.hannonhill.com/convert-time-stamps-using-xslt-formats
(current-time-convert.xslt )
but get this error: java.lang.NullPointerException. The error
persists when I reference the javascript code externally.
Any help would be much appreciated.
Attached is the data definition XML, my XSLT format and the XML being transformed.
- data_definition.xml 405 Bytes
- latest_news_index_block.xml 2 KB
- latest_news_format.xsl 1.5 KB
Comments are currently closed for this discussion. You can start a new one.
2 Posted by Kris on 01 Jun, 2010 08:55 PM
Can't you just use the format-date format in the _custom site? You can just include (the path may be different in your implementation)
<xsl:include href="site://_common/formats/include/format-date"/>in your format and then call the format-date template on the date you want to format. If you look in the format-date file, it has documentation on usage and appropriate masks.
HTH,
Kris
3 Posted by espanae on 01 Jun, 2010 09:18 PM
I don't see format-date in my implementation. I do have /common/stylesheets/include/convert-date, however.
4 Posted by Kris on 01 Jun, 2010 09:25 PM
Being new to Cascade, I do not have experience with older versions. What version are you on? I have format-date in version 6.4.6 as well as the 6.7 beta. Assuming you are on an older version, perhaps HH renamed it in later versions. Hopefully it has the same functionality.
5 Posted by T.S.Lindsey on 01 Jun, 2010 09:47 PM
[edit]oops. nevermind.
Support Staff 6 Posted by Tim on 03 Jun, 2010 01:52 PM
The reason you are getting a NullPointerException is likely due to the fact that the XSLT Format is trying to convert a date value which does not exist in the context of your index block XML. In your XSLT Format, you have:
This Format assumes that the XML tree contains the path:
/system-index-block/system-page/system-data-structure/publishHowever, if you look at the index block XML, no
<system-page>elements contain any<system-data-structure>elements. To correct this, you need to edit your index block and make sure that the option to Render page XML inline only for current page is checked. You will also probably want to check the option to Append Calling Page Data. After doing so, your XSLT Format may require some slight changes.Try making those changes to the index block then attach the XML output for the new index block as it looks when it is attached to your page.
Tim closed this discussion on 15 Jun, 2010 05:08 PM.
espanae re-opened this discussion on 21 Jun, 2010 03:36 PM
7 Posted by espanae on 21 Jun, 2010 03:36 PM
I modified the index block (news_feed.xml) per your suggestions and referenced the date value without the date-converter:convertDate() function (in the XSLT format) and the page rendered with no errors.
<xsl:value-of select="publish"/>When I reference the date value with the date-converter:convertDate() function I get the NullPointerException error again.
<xsl:value-of select="date-converter:convertDate(publish)"/>I'm using Cascade Server 6.2.
Support Staff 8 Posted by Tim on 21 Jun, 2010 04:00 PM
What does your XSLT Format look like now? I just pasted your latest index block XML into my local instance (as an XML block) and copied your original XSLT Format into my instance. Attaching those to a region on a page displayed the proper results for me:
9 Posted by espanae on 21 Jun, 2010 06:32 PM
That's good news. I don't think I changed the XSLT Format but I've attached my code so you can compare it with what you have.
Support Staff 10 Posted by Tim on 21 Jun, 2010 08:46 PM
Hmm, this is working over here. The index block XML output that you attached earlier - is that a snippet from your index block or is that the entire thing? The only reason I ask is because if that is only a portion of the index block, you may have some pages appearing in your full index block that don't have a
<publish>element (which would cause a NPE when your Format tried to convert the date).If you still have problems, try taking your XML that you've attached here and create a new XML block. Then, plug it into a region along with your XSLT Format and see if you get the same results that I did.
11 Posted by espanae on 21 Jun, 2010 09:29 PM
Weird. The index block I attached earlier should be the entire thing. I tried your second suggestion anyway. I created a new XML block using the XML I attached and then plugged it into the region. But I still get the NPE.
Let me know if you have any other ideas I can try. Thanks.
Support Staff 12 Posted by Tim on 22 Jun, 2010 02:40 PM
Would it be possible for me to access your instance to take a look at the asset in question? If so, please send an email to [email blocked] with the URL and administrator credentials and I would be happy to take a look. In the email, be sure to reference this forum post and also provide the location of the asset.
Thanks
13 Posted by espanae on 22 Jun, 2010 05:27 PM
I thought you'd never ask. I sent an email to [email blocked].
On a related note, will I have access to the library that Kris referenced in the second post, once we upgrade to 6.4? I don't have a folder called
_custom.Thanks.
Support Staff 14 Posted by Tim on 22 Jun, 2010 09:10 PM
Ok, I think we may have an idea as to what could be going on here. Given that the same exact XML and Format worked fine in my local instance, I tried narrowing down the differences between environments. If you are using Mac OS X (which I believe is the case), you need to make sure that you have executed a few commands to fix a compatibility issue with Apple's JVM and Xalan Extensions. Check out our Mac OS X Installation instructions and be sure to look at NOTE under Step 6.
Let me know if this corrects the problem!
Thanks
15 Posted by espanae on 25 Jun, 2010 02:30 PM
Tim, that did the trick. Thanks.
Funny story, though. Our system administrator first tried executing the commands on our test instance of Cascade (6.4.6), but he only found the second file.
Result: The NullPointerException error disappeared and the page rendered, but the Format didn't produce any output.
Then he tried it on our production instance of Cascade (6.2). He moved the first file but didn't find the second file.
Result: It worked. The page rendered with formatted dates.
Any idea why two Mac servers, that are supposed to be identical, somehow had different files?
Support Staff 16 Posted by Tim on 25 Jun, 2010 02:42 PM
Good deal! Glad to hear things are working now.
As far as the two Mac servers are concerned, I'm not sure why the files would be missing. Perhaps there was a system update to one of the machines at one point in time?
One other thing you will want to verify is that you have the Content Preference to Enable Xalan Javascript extensions checked. Without this option, the XSLT Format will likely not output anything for the date.
Tim closed this discussion on 25 Jun, 2010 02:42 PM.