W
wingnut144
I have the following XML file:
<?xml version="1.0" encoding="utf-8"?>
<class>
<sdate>9/10/07</sdate>
<special>1,2</special>
<inst>Max Callao</inst>
<sdate>10/22/07</sdate>
<special>1,2</special>
<inst>Max Callao</inst>
<sdate>11/26/07</sdate>
<special>3</special>
<inst>Max Callao</inst>
<sdate>1/28/08</sdate>
<special>1,2</special>
<inst>Max Callao</inst>
<sdate>3/10/08</sdate>
<special>3</special>
<inst>Max Callao</inst>
<sdate>4/21/08</sdate>
<special>1,2</special>
<inst>Max Callao</inst>
</class>
And am displaying it with the following Coldfusion code:
<cffile action="read" file="C:\Inetpub\wwwroot\SalleBoise\sb1.xml"
variable="xmldoc">
<cfset mydoc = XmlParse(xmldoc)>
<cfset mydoc_stuff = XmlSearch(mydoc, "/class/sdate")>
<cfset cl_inst= XmlSearch(mydoc, "/class/inst")>
<cfset cl_spec=xmlSearch(mydoc, "/class/special")>
<cfset CurrDate=dateformat(now(),"mmmm d,yyyy")>
<!--- Starts off the inital item count --->
<cfset icount=1>
<div align="left" style="margin:0 auto;">
<cfloop index="mydoc_item" from="1" to=#ArrayLen(mydoc_stuff)#>
<cfset mydoc_data = mydoc_stuff[mydoc_item].XmlText>
<cfset mydoc_inst= cl_inst[mydoc_item].XmlText>
<cfset mydoc_spec=cl_spec[mydoc_item].XmlText>
<!--- Find the number of days between the start of the session and the
current date --->
<cfset temp=datediff("d",mydoc_data,CurrDate)>
<!--- Send end date for classes, calculated by adding 23 days to start
of beginning of class --->
<cfset temp2=dateformat(dateadd("d",23,mydoc_data),"m/d/yy")>
<!--- Check to see if date of classes are more than 7 months out, or
are more than 5 days (based on class ending date) in the past, if so,
don't display --->
<cfif (datediff("m",CurrDate,mydoc_data) gte 7) or
(datediff("d",temp2,CurrDate) gte 5)>
<cfelse>
<!--- If class date is more than 23 days old, mark as 'not available'
--->
<cfif temp gt 23>
<img src="images/small_no_class.gif" style="padding-right:5px; margin-
left:25px;" alt="Session ended" /><cfoutput>Session #icount#: <span
class="fake_strikethrough">#mydoc_data# -- #temp2#</span><br />
<div align="left" style="font:Arial, Helvetica, sans-serif; font-size:
10px; float:left; padding-left:62px;">Instructor: #mydoc_inst#</
div><br clear="left">
<div style="padding-left:62px; float:left; font-size:10px;">Class
type: <cfloop list="#mydoc_spec#" delimiters="," index="i">
<cfswitch expression="#i#">
<cfcase value="1">
Beginner,
</cfcase>
<cfcase value="2">
Intermediate
</cfcase>
<cfcase value="3">
Workshop session
</cfcase>
</cfswitch>
</cfloop>
</div><br clear="left">
<!--- <cfif len(mydoc_spec) gte 1><div style="padding-left:10px;
float:left; font-size:9px;"><strong>Workshop session</strong></div><br
clear="left"></cfif> --->
</cfoutput>
<!--- If class more than 2 days old AND less than the ending date of
23 days, mark as 'in session' --->
<cfelseif (datediff("d",mydoc_data,CurrDate) gt 2) and
(datediff("d",mydoc_data,CurrDate) lte 23)>
<img src="images/small_in_session_class.gif" style="padding-right:5px;
margin-left:25px;" alt="In session" /><cfoutput>Session #icount#:
#mydoc_data# -- #temp2#<br />
<div align="left" style="font:Arial, Helvetica, sans-serif; font-size:
10px; float:left; padding-left:62px;">Instructor: #mydoc_inst#</
div><br clear="left">
<div style="padding-left:62px; float:left; font-size:10px;">Class
type: <cfloop list="#mydoc_spec#" delimiters="," index="i">
<cfswitch expression="#i#">
<cfcase value="1">
Beginner,
</cfcase>
<cfcase value="2">
Intermediate
</cfcase>
<cfcase value="3">
Workshop session
</cfcase>
</cfswitch>
</cfloop>
</div><br clear="left">
</cfoutput>
<cfelse>
<!--- Otherwise mark the class as available to sign up for --->
<cfif datediff("d",CurrDate, mydoc_data) lte 30>
<!--- Display register icon if class is 30 days or less before start
of class --->
<div class="reg_img" style="float:right;"><a href="https://
www.memberst.com/Programs/Sessions.aspx?id=C4B5D9EB-55B1-41EB-99AE-2251ECEAD36C"
target="_blank"><cfoutput>
<img src="images/small_online_register.gif" alt="Register for
#mydoc_data# class" name="register" width="15" height="15" border="0"
style="padding-left:5px;" title="Register for #mydoc_data# class"/></
cfoutput></a></div>
</cfif>
<img src="images/small_yes_class.gif" style="padding-right:5px; margin-
left:25px;" alt="Available" /><cfoutput>Session #icount#:
#mydoc_data# -- #temp2#<br />
<div align="left" style="font:Arial, Helvetica, sans-serif; font-size:
10px; float:left; padding-left:62px;">Instructor: #mydoc_inst#</
div><br clear="left">
<div style="padding-left:62px; float:left; font-size:10px;">Class
type: <cfloop list="#mydoc_spec#" delimiters="," index="i">
<cfswitch expression="#i#">
<cfcase value="1">
Beginner,
</cfcase>
<cfcase value="2">
Intermediate
</cfcase>
<cfcase value="3">
Workshop session
</cfcase>
</cfswitch>
I would like to find a way I can add an additional date at the bottom
of the xml file, and still have the dates sorted correctly. I was
told about XSLT, but since I need the Coldfusion part of the code to
remain, I'm not sure how I can 'sort' the XML file before its looped
over by the Coldfusion.
Does anyone have any suggestions?
Thanks!
<?xml version="1.0" encoding="utf-8"?>
<class>
<sdate>9/10/07</sdate>
<special>1,2</special>
<inst>Max Callao</inst>
<sdate>10/22/07</sdate>
<special>1,2</special>
<inst>Max Callao</inst>
<sdate>11/26/07</sdate>
<special>3</special>
<inst>Max Callao</inst>
<sdate>1/28/08</sdate>
<special>1,2</special>
<inst>Max Callao</inst>
<sdate>3/10/08</sdate>
<special>3</special>
<inst>Max Callao</inst>
<sdate>4/21/08</sdate>
<special>1,2</special>
<inst>Max Callao</inst>
</class>
And am displaying it with the following Coldfusion code:
<cffile action="read" file="C:\Inetpub\wwwroot\SalleBoise\sb1.xml"
variable="xmldoc">
<cfset mydoc = XmlParse(xmldoc)>
<cfset mydoc_stuff = XmlSearch(mydoc, "/class/sdate")>
<cfset cl_inst= XmlSearch(mydoc, "/class/inst")>
<cfset cl_spec=xmlSearch(mydoc, "/class/special")>
<cfset CurrDate=dateformat(now(),"mmmm d,yyyy")>
<!--- Starts off the inital item count --->
<cfset icount=1>
<div align="left" style="margin:0 auto;">
<cfloop index="mydoc_item" from="1" to=#ArrayLen(mydoc_stuff)#>
<cfset mydoc_data = mydoc_stuff[mydoc_item].XmlText>
<cfset mydoc_inst= cl_inst[mydoc_item].XmlText>
<cfset mydoc_spec=cl_spec[mydoc_item].XmlText>
<!--- Find the number of days between the start of the session and the
current date --->
<cfset temp=datediff("d",mydoc_data,CurrDate)>
<!--- Send end date for classes, calculated by adding 23 days to start
of beginning of class --->
<cfset temp2=dateformat(dateadd("d",23,mydoc_data),"m/d/yy")>
<!--- Check to see if date of classes are more than 7 months out, or
are more than 5 days (based on class ending date) in the past, if so,
don't display --->
<cfif (datediff("m",CurrDate,mydoc_data) gte 7) or
(datediff("d",temp2,CurrDate) gte 5)>
<cfelse>
<!--- If class date is more than 23 days old, mark as 'not available'
--->
<cfif temp gt 23>
<img src="images/small_no_class.gif" style="padding-right:5px; margin-
left:25px;" alt="Session ended" /><cfoutput>Session #icount#: <span
class="fake_strikethrough">#mydoc_data# -- #temp2#</span><br />
<div align="left" style="font:Arial, Helvetica, sans-serif; font-size:
10px; float:left; padding-left:62px;">Instructor: #mydoc_inst#</
div><br clear="left">
<div style="padding-left:62px; float:left; font-size:10px;">Class
type: <cfloop list="#mydoc_spec#" delimiters="," index="i">
<cfswitch expression="#i#">
<cfcase value="1">
Beginner,
</cfcase>
<cfcase value="2">
Intermediate
</cfcase>
<cfcase value="3">
Workshop session
</cfcase>
</cfswitch>
</cfloop>
</div><br clear="left">
<!--- <cfif len(mydoc_spec) gte 1><div style="padding-left:10px;
float:left; font-size:9px;"><strong>Workshop session</strong></div><br
clear="left"></cfif> --->
</cfoutput>
<!--- If class more than 2 days old AND less than the ending date of
23 days, mark as 'in session' --->
<cfelseif (datediff("d",mydoc_data,CurrDate) gt 2) and
(datediff("d",mydoc_data,CurrDate) lte 23)>
<img src="images/small_in_session_class.gif" style="padding-right:5px;
margin-left:25px;" alt="In session" /><cfoutput>Session #icount#:
#mydoc_data# -- #temp2#<br />
<div align="left" style="font:Arial, Helvetica, sans-serif; font-size:
10px; float:left; padding-left:62px;">Instructor: #mydoc_inst#</
div><br clear="left">
<div style="padding-left:62px; float:left; font-size:10px;">Class
type: <cfloop list="#mydoc_spec#" delimiters="," index="i">
<cfswitch expression="#i#">
<cfcase value="1">
Beginner,
</cfcase>
<cfcase value="2">
Intermediate
</cfcase>
<cfcase value="3">
Workshop session
</cfcase>
</cfswitch>
</cfloop>
</div><br clear="left">
</cfoutput>
<cfelse>
<!--- Otherwise mark the class as available to sign up for --->
<cfif datediff("d",CurrDate, mydoc_data) lte 30>
<!--- Display register icon if class is 30 days or less before start
of class --->
<div class="reg_img" style="float:right;"><a href="https://
www.memberst.com/Programs/Sessions.aspx?id=C4B5D9EB-55B1-41EB-99AE-2251ECEAD36C"
target="_blank"><cfoutput>
<img src="images/small_online_register.gif" alt="Register for
#mydoc_data# class" name="register" width="15" height="15" border="0"
style="padding-left:5px;" title="Register for #mydoc_data# class"/></
cfoutput></a></div>
</cfif>
<img src="images/small_yes_class.gif" style="padding-right:5px; margin-
left:25px;" alt="Available" /><cfoutput>Session #icount#:
#mydoc_data# -- #temp2#<br />
<div align="left" style="font:Arial, Helvetica, sans-serif; font-size:
10px; float:left; padding-left:62px;">Instructor: #mydoc_inst#</
div><br clear="left">
<div style="padding-left:62px; float:left; font-size:10px;">Class
type: <cfloop list="#mydoc_spec#" delimiters="," index="i">
<cfswitch expression="#i#">
<cfcase value="1">
Beginner,
</cfcase>
<cfcase value="2">
Intermediate
</cfcase>
<cfcase value="3">
Workshop session
</cfcase>
</cfswitch>
I would like to find a way I can add an additional date at the bottom
of the xml file, and still have the dates sorted correctly. I was
told about XSLT, but since I need the Coldfusion part of the code to
remain, I'm not sure how I can 'sort' the XML file before its looped
over by the Coldfusion.
Does anyone have any suggestions?
Thanks!