473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Getting XML data depending on day

Hi,

Im having trouble displaying only the info I want from my xml file depending on the day or of the week.

Would be v.gratefull for any code snippets!

xml
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <WRAP>
  3. <DOW>
  4. <DAY>1</DAY>
  5. <TASK>Doctors</TASK>
  6. <DAY>TWO</DAY>
  7. <TASK>Walk the Dog</TASK>
  8. </DOW>
  9. <DOW>
  10. <DAY>2</DAY>
  11. <TASK>Doctors</TASK>
  12. <DAY>TWO</DAY>
  13. <TASK>Walk the Dog</TASK>
  14. </DOW>
  15. </WRAP>
xsl
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <xsl:stylesheet version="1.0"
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.  
  5. <xsl:template match="/">
  6.   <html>
  7.  
  8.   <body>
  9.     <table>
  10.       <xsl:for-each select="WRAP/DOW">
  11.     <xsl:choose>
  12.           <xsl:when test="DAY = '1'">
  13.           <xsl:value-of select='TASK'/>
  14.           </xsl:when>
  15.         </xsl:choose>
  16.       </xsl:for-each>
  17.     </table>
  18.   </body>
  19.   </html>
  20. </xsl:template>
  21.  
  22. </xsl:stylesheet>
but where

Expand|Select|Wrap|Line Numbers
  1. <xsl:when test="DAY = '1'">
im trying(only way i know) is to do something like this

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. var current_date = new Date();
  3. var today = current_date.getDay();
  4. </script>
  5. ...
  6. <xsl:when test="DAY = today">
thanks

steve
Apr 14 '08 #1
4 1576
pronerd
392 Expert 256MB
If I follow this I think what you want for the first part is this:

Expand|Select|Wrap|Line Numbers
  1.       <xsl:for-each select="//WRAP/DOW[@DAY = '1']" >
  2.             <xsl:value-of select="@TASK" />
  3.       </xsl:for-each>
  4.  



For the second part the syntax for the compare should be like this :

Expand|Select|Wrap|Line Numbers
  1.  
  2. <xsl:variable name="dayOfWeek">2</xsl:variable>
  3. ...
  4. <xsl:when test="@DAY = $dayOfWeek">
  5. ...
  6.  

You will need to look up the xPath functions to see which ones will return the numeral day of the week.
http://www.w3schools.com/xpath/xpath...s.asp#datetime
Apr 15 '08 #2
heya,

thanks for your info...

i managed to get the following. but stuck with makeing the today variable global inorder to use it in my <when test>

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2.  
  3. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4. <xsl:template match="/">
  5.   <html>
  6.   <body>
  7.   <link media="all" rel="stylesheet" type="text/css" href="thecss.css" />
  8.     <script language="JavaScript">
  9.       var cDate = new Date();
  10.       var today = cDate.getDay();
  11.       <xsl:variable name="tday">today</xsl:variable>
  12.       alert(<xsl:value-of select='$tday' />);
  13.     </script>
  14.   <div class="stitle">Schedule</div>
  15.   <xsl:for-each select="SCHEDULE/DOW">
  16.     <xsl:choose>
  17.     <xsl:when test="DAY = $tday"> <!-- tday out of scope -->
  18.       <div class="date">
  19.         <xsl:value-of select="DATE" />
  20.       </div>
  21.       <div class="schedule">
  22.       <xsl:for-each select="SHOW">
  23.       <div>
  24.         <div class="stime">
  25.           <xsl:value-of select="STIME" /> -
  26.         </div>
  27.         <div class="etime">
  28.           <xsl:value-of select="ETIME" />
  29.         </div>
  30.         <div class="title">
  31.           <xsl:value-of select="TITLE" />
  32.         </div>
  33.         <div class="description">
  34.           <xsl:value-of select="DESCRIPTION" />
  35.         </div>
  36.       <br />
  37.       </div>
  38.       </xsl:for-each>
  39.       </div>
  40.     </xsl:when>
  41.     </xsl:choose>
  42.     </xsl:for-each>
  43.   </body>
  44.   </html>
  45. </xsl:template>
  46. </xsl:stylesheet>
any ideas?

thanks

steve
Apr 17 '08 #3
jkmyoung
2,057 Expert 2GB
Another problem here: <xsl:variable name="tday">today</xsl:variable>
You'll just have a variable with the string "today"
Apr 18 '08 #4
jkmyoung
2,057 Expert 2GB
What are you using to process the xsl? IE? javascript of some sort? PHP?

It's easier if you can pass in a parameter to the xsl with PHP or javascript etc...
Apr 19 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like...
5
by: Brandons of mass destruction | last post by:
Ok, I work for a small newspaper thats looking to translate our content to the web. XML sounds like a good way to do this, but i'm a little confused. Is it possible to have <b> and <i> tags in...
3
by: FaXiA | last post by:
Hi all, I'm working on a program that reads a structure from a file (1000 records). The file read part works great, but I'm hitting a roadblock on howto read the data from the pointer. I'm...
0
by: Alpha | last post by:
I have a dataset containing a table as a data source for a list box in the windows application depending on which radio button the user selects. The table is disposed when the user clicks on other...
10
by: darrel | last post by:
I have this structure: mypage.aspx (class = mypage) myusercontro.ascx On the mypage.aspx I can declare a variable: animal = "monkey" I can read this from the UC by simply doing this:...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
10
by: Paul H | last post by:
I am trying to get the spec for a database. The trouble is the client frequently blurts out industry jargon, speaks insanely quickly and is easily sidetracked. They are currently using around 30...
3
by: itfetish | last post by:
I've been programming a bit in PHP and then recently learnt classic ASP for projects at work, now I'm working on another project that they want done in .net. I've got my head around web parts, that...
11
by: Armin Zingler | last post by:
"Bill Schanks" <wschanks@gmail.comschrieb Try to execute lvMembers.beginupdate before filling and lvMembers.endupdate
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.