Click to See Complete Forum and Search --> : [RESOLVED] Current Date? Deadline approaching!


brasspenguins
12-30-2007, 06:02 AM
Aaaah! So I took on way more than I can handle, and I've hit crunch time. Quick and to the point:

Is there any way to get the current date in an xml/xslt file? I don't care what format it's in or what method is used anymore (except dotnet). I just need a lead. I've been searching google for days and still can't find any help.


In depth:

I have scripture broken down and organized into an xml file. I wrote a very effective xsl file to format it and I'm very happy with how it's working. However, the true purpose of this feature is to display portions of the scripture depending on date, instead of the entire file. Right now it's dependent on me to update the xml file in order to display each day's assigned reading. That's obviously inefficient and I certainly don't have the time to do this forever. ;) I would rather add all of the data to the file and have the computers do all the thinking.


Grateful thanks ahead of time! :D

TheBearMay
12-31-2007, 11:45 AM
If you just want to display the date, inside the XSL file you could place:


<script type="text/javascript">
<![CDATA[
var cDate= new Date();
document.body.appendChild(document.createTextNode(cDate));
]]>
</script>

To use the classic CD Catalog example:

?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>CD Collection</h2>
<script type="text/javascript">
<![CDATA[
var cDate= new Date();
document.body.appendChild(document.createTextNode(cDate));
]]>
</script>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

brasspenguins
12-31-2007, 02:51 PM
:eek: wOw That simple? Geez, how did I miss that? Thanks.

Before I declare this resolved, may I assume that I can use similar javascript functions to just return the numerical date (e.g. 31) or the day of the year (e.g. 365)?

TheBearMay
12-31-2007, 03:02 PM
The Date object exposes several see: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Date

brasspenguins
01-01-2008, 02:18 PM
Thanks this REALLY helped. Great resources here.