|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Showing Records Within Last 30 Days
I have a xml file of a directory of video files which I have tagged with the date that the file was added. I would like to create a link on my main page to only show the files that have been added in the last 30 days. The idea is to compare the current date with the date in the added tag and select the records. Any help to get started would be greatly appreciated.
XML File: Code:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="main.xsl"?>
<catalog>
<video>
<file>
<label>S</label>
<name>Sample1.avi</name>
<size>176 MB</size>
<created>5/3/2009 7:07:31 AM</created>
<added>6/11/2009 2:10:23 PM</added>
<tags />
</file>
</video>
<video>
<file>
<label><A/label>
<name>Ace1.avi</name>
<size>17 MB</size>
<created>5/3/2009 8:00:23 AM</created>
<added>4/11/2008 2:10:23 PM</added>
<tags />
</file>
</video>
</catalog>
XSL File: Code:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="choice" />
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<table width="100%" border="1">
<tbody>
<tr bgColor="#0033ff">
<td width="100%">
<font face="Arial" size="5">
<font color="#ffffff"><strong>Label - </strong>
<strong><xsl:value-of select="$choice"/></strong>
</font>
</font>
</td>
</tr>
</tbody>
</table>
<xsl:for-each select="catalog/video">
<xsl:sort select="file/name"/>
<xsl:if test="$choice=file/label">
<xsl:for-each select="file">
<table width="100%" border="1"><tbody>
<tr bgColor="#005599">
<td colspan="2">
<p align="center">
<font face ="Arial">
<font color="ffffff">
<strong>Filename</strong>
<xsl:value-of select="Filename"/>
</font>
</font>
</p>
</td>
<td colspan="2">
<p align="center">
<font face ="Arial">
<font color="ffffff">
<strong>Size</strong>
<xsl:value-of select="Filename"/>
</font>
</font>
</p>
</td>
<td colspan="2">
<p align="center">
<font face ="Arial">
<font color="ffffff">
<strong>Date Created</strong>
<xsl:value-of select="Filename"/>
</font>
</font>
</p>
</td>
</tr>
<tr>
<td colspan="2">
<p align="center">
<font face="Arial">
<xsl:element name = "a">
<xsl:attribute name="href"><xsl:value-of select="filepath"/>
</xsl:attribute>
<xsl:value-of select="name"/>
</xsl:element>
</font>
</p>
</td>
<td colspan="2">
<p align="center">
<font face="Arial">
<xsl:value-of select="size"/>
</font>
</p>
</td>
<td colspan="2">
<p align="center">
<font face="Arial">
<xsl:value-of select="created"/>
</font>
</p>
</td>
</tr>
<tr>
<td><img src="{image01}"/></td>
<td><img src="{image02}"/></td>
<td><img src="{image03}"/></td>
<td><img src="{image04}"/></td>
<td><img src="{image05}"/></td>
<td><img src="{image06}"/></td>
</tr>
</tbody>
</table>
<table width="100%" border="1"><tbody>
<tr bgColor="#666666">
<td colspan="1">
<p align="left">
<font face="Arial" size="2.5">
<font color="ffffff">
<strong>Tags</strong>
</font>
</font>
</p>
</td>
</tr>
<tr>
<td width="100%">
<xsl:for-each select="tags/tag">
<xsl:sort select="."/>
<font face="Arial" size="2">
<xsl:element name ="a">
<xsl:attribute name="href">videodb.html?tag=<xsl:value-of select="."/>
</xsl:attribute>
<font color="0066cc">
<xsl:value-of select="."/>
</font>
</xsl:element>
</font>
</xsl:for-each>
</td>
</tr>
</tbody>
</table>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|
|
#2
|
|||
|
|||
|
First of all, you'd have to pass in a date. Either the current date, or the date for 30 days ago. It's easier for xslt if you pass in the date 30 days ago, since xslt is not very good for numeric computation.
Due to the layout of your xslt, it'd be even better if you passed in the year, month and day seperately. <xsl:param name="year"/> <xsl:param name="month"/> <xsl:param name="day"/> When you say only show the files that have been added, do you mean still show the videos, but not the older files, or not show the videos entirely? Do you ever have multiple files to a video? Assuming 1 file to a video, and not showing the entire video, and further assuming a d/m/yyyy layout to your date: Code:
<xsl:for-each select="catalog/video">
<xsl:sort select="file/name"/>
<xsl:variable name="vday" select="substring-before(file/added,'/')"/>
<xsl:variable name="vmonth" select="substring-before(substring-after(file/added,'/'),'/')"/>
<xsl:variable name="vyear" select="substring(substring-after(substring-after(file/added,'/'),'/'),1,4)"/>
<xsl:if test="(vyear > $year) or
((vyear = $year) and
(vmonth > $month)) or
((vyear = $year) and
(vmonth = $month) and
(vday >= $day))">
...what you already have goes here...
</xsl:if>
|
|
#3
|
|||
|
|||
|
jkmyoung, thanks for the reply and help.
The XML creates 1 file to a video. So, when a link is clicked on the main HTML page (What's New), I want to filter the entire XML file and only show the videos which have an added date of 30 days or less. Ill give this a try and let you know the results. |
|
#4
|
|||
|
|||
|
Resolved!
jkmyoung,
There WAS an issue with my Javascript and I resolved it. Its working perfectly. Thanks for your help. I just have to work on finding a date 30 days in the past with JS. Thanks again. Last edited by ignignokt : June 17th, 2009 at 11:44 AM. Reason: Resolved |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Showing Records Within Last 30 Days |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|