I'll suggest an entirely different solution just for inspiration; I don't exactly know what you mean by docType, but I'm assuming you have a container document of some sorts, containing seven documents named after the weekdays - whether they're the same docType with different names (@nodeName) or 7 unique docTypes ("Monday" docType, "Tuesday" docType etc.) doesn't matter - this would work:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umb="urn:umbraco.library"
xmlns:date="urn:Exslt.ExsltDatesAndTimes"
xmlns:make="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="umb date make"
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="currentPage" select="/root/Website/Textpage[@id]" />
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<!-- Grab the container of the Weekday docs -->
<xsl:variable name="weekdayContainer" select="$siteRoot/Weekdays" />
<!-- XML variable for easy lookup -->
<xsl:variable name="weekdays-mapper">
<day id="1">Sunday</day>
<day id="2">Monday</day>
<day id="3">Tuesday</day>
<day id="4">Wednesday</day>
<day id="5">Thursday</day>
<day id="6">Friday</day>
<day id="7">Saturday</day>
</xsl:variable>
<xsl:variable name="weekdays" select="make:node-set($weekdays-mapper)" />
<!-- Get the day of the week -->
<xsl:variable name="today" select="date:dayinweek()" />
<xsl:template match="/">
<!-- (1) If your docTypes are of the same type (e.g. "Weekday") and just named after the day, use @nodeName -->
<xsl:apply-templates select="$weekdayContainer/Weekday[@nodeName = $weekdays/day[@id = $today]]" />
<!-- (2) If you have 7 different docTypes named "Sunday", "Monday" etc. use name() -->
<xsl:apply-templates select="$weekdayContainer/*[name() = $weekdays/day[@id = $today]]" />
</xsl:template>
<!-- Template for a Weekday - change to your actual docType name (1) -->
<xsl:template match="Weekday">
<p>
Hey this is <xsl:value-of select="@nodeName" />.
</p>
</xsl:template>
<!-- = = = = = = = = = = -->
<!-- Templates for the daily doctypes (2) -->
<xsl:template match="Monday">
<p>So this is Monday, huh?</p>
</xsl:template>
<xsl:template match="Tuesday">
<p>Aha - Tuesday!</p>
</xsl:template>
<xsl:template match="Wednesday">
<p>Yay - it's Wednesday!</p>
</xsl:template>
<!-- Etc... -->
</xsl:stylesheet>
Hope this helps you - otherwise, I should probably issue a refund for the time you spent reading it :-)
Wow, Chriztian, thanks! Well worth the time reading it ;-)
I think I have option 2. My tree looks like this:
listpage - bar 1 - monday - tuesday - wednesday - etc - bar 2 - monday - etc. - bar 3
Depending on the day of the week I the listpage shows a list of what all bars have to offer that day. The XSLT for displaying the items is exactly the same for every day, except the xpath is different.
<xsl:if test="$weekday = '4'">
<xsl:for-each select="$currentPage/bar/wednesday [@isDoc]">
show some stuff from the wednesday pages
</xsl:for-each>
</xsl:if>
<xsl:if test="$weekday = '5'">
<xsl:for-each select="$currentPage/bar/thursday [@isDoc]">show some stuff from the thursday pages </xsl:for-each> </xsl:if>
f I understand correctly I still have to make a template for every day of the week. My thoughts were to check which day it is, depending on that set a variable and pass that to the xpath. I do not know if that can be done. I tried, but then I get lots of errors ;-)
If I understand correctly, you don't actually need separate templates in the XSLT - you just need to select only "mondays", "wednesdays" etc. when you apply them. And you can do this using the name() function:
(Remember to lowercase the weekdays in the XML variable, if needed - your sample seems to indicate that...)
Then create a single template for display - have it match any node with a <bar> parent:
<xsl:template match="bar/*">
<!-- $today was created at the root level and thus global -->
<h2><xsl:value-of select="$today" /></h2>
<p>
<!-- do stuff -->
</p>
</xsl:template>
The apply-templates instruction makes sure to select the right nodes, and since $today was created outside of the templates, it's global and can be used inside any template.
if then statement in XSLT?
I made an XSLT which shows a different docType for every day of the week. I have set the weekdays:
<xsl:variable name="today" select="Exslt.ExsltDatesAndTimes:dayinweek()"/> ... <xsl:if test="$today = '2'"> call docType "Monday" </xsl:if> <xsl:if test="$today = '3'"> call DocType "Tuesday" </xsl:if>
Now I copy the same piece of XSLT for the seven weekdays. Is is possible to set a string depending on the outcome of another string?
Something like if $today = "4" then $docType = "Wednesday"?
Thanks,
Ralph
check this http://www.w3schools.com/xsl/xsl_choose.asp
Hi Eran,
Thanks for your quick reply!
Can I use <xsl:choose> to set a <xsl:variable> ?
<xsl:variable name="day">
</xsl:variable>
Hi Ralph,
I'll suggest an entirely different solution just for inspiration; I don't exactly know what you mean by docType, but I'm assuming you have a container document of some sorts, containing seven documents named after the weekdays - whether they're the same docType with different names (@nodeName) or 7 unique docTypes ("Monday" docType, "Tuesday" docType etc.) doesn't matter - this would work:
/Chriztian
Wow, Chriztian, thanks! Well worth the time reading it ;-)
I think I have option 2. My tree looks like this:
listpage
- bar 1
- monday
- tuesday
- wednesday
- etc
- bar 2
- monday
- etc.
- bar 3
Depending on the day of the week I the listpage shows a list of what all bars have to offer that day. The XSLT for displaying the items is exactly the same for every day, except the xpath is different.
f I understand correctly I still have to make a template for every day of the week. My thoughts were to check which day it is, depending on that set a variable and pass that to the xpath. I do not know if that can be done. I tried, but then I get lots of errors ;-)
What's the best thing to do?
Thanks for the help!
Ralph
Hi Ralph,
If I understand correctly, you don't actually need separate templates in the XSLT - you just need to select only "mondays", "wednesdays" etc. when you apply them. And you can do this using the name() function:
(Remember to lowercase the weekdays in the XML variable, if needed - your sample seems to indicate that...)
Then create a single template for display - have it match any node with a <bar> parent:
The apply-templates instruction makes sure to select the right nodes, and since $today was created outside of the templates, it's global and can be used inside any template.
/Chriztian
Chriztian,
You truly are the XSLT king! Thanks a million!
Ralph
Hi,
I want my logo to print only in first and second pages and not in rest of the pages
I have used the below codes but its printing in first and also in the rest of the pages
Could anyone help me to reach out this..
is working on a reply...