|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
XSL date
Hi there,
is it possible to show a certain part of an xml date with xsl? ie. Code:
<MONDAY> <TASK>GO TO DOCTORS</TASK> </MONDAY> <TUESDAY> <TASK>WALK THE DOG</TASK> </TUESDAY> xsl. Code:
if tuesday... show - task (walk the dog) could anyone give me a small code snippet, so i get the jist of it. Thanks Steve |
|
#2
|
|||
|
|||
|
If you have XML roughly like this...
Code:
<WRAPPER> <DAYOFWEEK>TUESDAY</DAYOFWEEK> ... <MONDAY> <TASK>GO TO DOCTORS</TASK> </MONDAY> <TUESDAY> <TASK>WALK THE DOG</TASK> </TUESDAY> </WRAPPER> Then you could use the following XSL (untested) Code:
...
<td> Your task today is
<xsl:choose>
<xsl:when test="/WRAPPER/DAYOFWEEK = 'MONDAY'">
<xsl:value-of select='/WRAPPER/MONDAY/TASK'/>
</xsl:when>
...
<xsl:when test="/WRAPPER/DAYOFWEEK = 'SUNDAY'">
<xsl:value-of select='/WRAPPER/SUNDAY/TASK'/>
</xsl:when>
</xsl:choose>
</td>
...
__________________
"Badges? We ain't got no badges. We don't need to badges! I don't have to show you any stinkin' badges!!" |
|
#3
|
|||
|
|||
|
Thanks,
but how will it know when it is monday? just to show monday? steve |
|
#4
|
|||
|
|||
|
Quote:
You need to supply that information in the XML ... Code:
<WRAPPER> <DAYOFWEEK>TUESDAY</DAYOFWEEK> ... |
|
#5
|
|||
|
|||
|
heya,
thanks for your help... but i dont get it haha. I have an xml with mulitple 'tasks' for each day of the week. and i would like to only display the tasks for the current day. thanks again steve |
|
#6
|
|||
|
|||
|
this is how far i got so far
xml Code:
<?xml version="1.0" encoding="ISO-8859-1"?> <WRAP> <DOW> <DAY>1</DAY> <TASK>Doctors</TASK> <DAY>TWO</DAY> <TASK>Walk the Dog</TASK> </DOW> <DOW> <DAY>2</DAY> <TASK>Doctors</TASK> <DAY>TWO</DAY> <TASK>Walk the Dog</TASK> </DOW> </WRAP> xsl Code:
<?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>
<table>
<xsl:for-each select="WRAP/DOW">
<xsl:choose>
<xsl:when test="DAY = '1'">
<xsl:value-of select='TASK'/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
but where Code:
<xsl:when test="DAY = '1'"> im trying(only way i know) is to do something like this Code:
<script> var current_date = new Date(); var today = current_date.getDay(); </script> ... <xsl:when test="DAY = today"> thanks steve |
|
#7
|
|||
|
|||
|
Whatever you're using to process the XSLT should have the date in it. PHP? C#?
If you're processing the XML directly linking to the XSLT with a processing instruction, then you'd have to use either a javascript or XSLT 2.0 solution. eg fn:current-dateTime() http://www.w3schools.com/xpath/xpath_functions.asp#datetime |
|
#8
|
|||
|
|||
|
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> Code:
<?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>
<link media="all" rel="stylesheet" type="text/css" href="thecss.css" />
<script language="JavaScript">
var cDate = new Date();
var today = cDate.getDay();
<xsl:variable name="tday">today</xsl:variable>
alert(<xsl:value-of select='$tday' />);
</script>
<div class="stitle">Schedule</div>
<xsl:for-each select="SCHEDULE/DOW">
<xsl:choose>
<xsl:when test="DAY = $tday"> <!-- tday out of scope -->
<div class="date">
<xsl:value-of select="DATE" />
</div>
<div class="schedule">
<xsl:for-each select="SHOW">
<div>
<div class="stime">
<xsl:value-of select="STIME" /> -
</div>
<div class="etime">
<xsl:value-of select="ETIME" />
</div>
<div class="title">
<xsl:value-of select="TITLE" />
</div>
<div class="description">
<xsl:value-of select="DESCRIPTION" />
</div>
<br />
</div>
</xsl:for-each>
</div>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
any ideas? thanks steve |
|
#9
|
|||
|
|||
|
I needed that also, thanks.
![]() |
|
#10
|
|||
|
|||
|
As stated in the other forum
<xsl:variable name="tday">today</xsl:variable> Will give you a variable of string today. It will not provide the javascript variable value. |
|
#11
|
|||
|
|||
|
Quote:
it does work for me, when the alert function calls the value of tday.. it prints a number (day of the week) But how can i make that a global variable? thanks steve |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSL date |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|