I am doing a school assignment. One of the problems I have is to add a duration on to an existing date. I can't find any support for this problem with standard XSLT. So, I had a stab at using EXSLT which has an add method to do exactly what I want. However, I just can't get it working. Here is a the website for the method:

http://www.exslt.org/date/functions/add/index.html

I am using Eclipse with the Xslt plugin. The teacher said that Eclipse doesn't like EXSLT. So, could this be a problem with the IDE?

You will notice that the line <xsl:value-of select="date:add(Start, Duration)" /> is commented out because it is the line that causes errors. How can I get this line working?

Is there another way to add a duration to a date?

Anyway, here is the XSLT:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
	xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

	<!-- Import date EXSLT function -->
	<xsl:import href="date.add.xsl" />

	<!-- Ensure HTML is indented -->
	<xsl:output method="html" indent="yes" name="html" />

	<!-- Template for root element -->
	<xsl:template match="/">

		<!-- HTML Header including JavaScript for toggling cast div -->
		<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
				<title>TV Guide</title>
				<link rel="stylesheet" href="JukeBox.css" />
				<script type="text/javascript">

					function toggle(element) {
					if
					(element.style.display == 'none') {
					element.style.display = 'block';
					} else {
					element.style.display = 'none';
					}
					}
        
      			</script>
			</head>

			<!-- HTML Body -->
			<body>
				<!-- Title -->
				<h1>TV Guide</h1>

				<!-- Create the horizontal links at the top of the page -->
				<p>
					<xsl:apply-templates select="TVGuide/Channel/Name" />
				</p>

				<!-- Iterate through Channels -->
				<xsl:for-each select="TVGuide/Channel">

					<!-- Display Channel Title -->
					<h2 class="channel">

						<xsl:element name="a">
							<xsl:attribute name="name"><xsl:value-of
								select="Name" /></xsl:attribute>

							<xsl:attribute name="id"><xsl:value-of
								select="Name" /></xsl:attribute>
							<xsl:value-of select="Name" />
						</xsl:element>

					</h2>

					<!-- Iterate through Programs for Channel -->
					<xsl:for-each select="Program">

						<!-- Create the main div for the Program -->
						<xsl:element name="div">

							<!-- Determine whether or not the program should use the interesting 
								style -->
							<xsl:choose>
								<xsl:when
									test="@flag='interesting' or @flag='favorite' or @rating > 5">
									<xsl:attribute name="class">interesting</xsl:attribute>
								</xsl:when>
								<xsl:otherwise>
								</xsl:otherwise>
							</xsl:choose>

							<p>
								<!-- Display the date and time of the program -->
								<span class="date">
									<xsl:value-of select="Start" />
									<xsl:value-of select="' - '" />
									<!-- <xsl:value-of select="date:add(Start, Duration)" /> -->
								</span>
								<br />

								<!-- Display interesting, favorite, or StarTrek icons if necessary -->
								<xsl:choose>
									<xsl:when test="@flag='favorite'">
										<img src="favorite.gif" alt="[Favorite]" width="20"
											height="20" />
									</xsl:when>

									<xsl:when test="@flag='interesting'">
										<img src="interest.gif" alt="[Interest]" width="20"
											height="20" />
									</xsl:when>

									<xsl:otherwise>
									</xsl:otherwise>
								</xsl:choose>

								<xsl:choose>
									<xsl:when test="contains(Series, 'StarTrek')">
										<img src="StarTrek.gif" alt="[Star Trek]" width="20"
											height="20" />
									</xsl:when>
								</xsl:choose>


								<!-- Display the series title if there is a series -->
								<xsl:choose>
									<xsl:when test="Series!=''">
										<span class="title">
											<xsl:value-of select="Series" />
										</span>
									</xsl:when>
								</xsl:choose>

								<!-- Add a dash between series and title if both exist -->
								<xsl:choose>
									<xsl:when test="Series!='' and Title!=''">
										<xsl:text> - </xsl:text>
									</xsl:when>
								</xsl:choose>

								<!-- Display title if it exists and change the formatting if there 
									is a series -->
								<xsl:choose>
									<xsl:when test="Title!=''">
										<xsl:choose>
											<xsl:when test="Series!=''">
												<span class="subtitle">
													<xsl:value-of select="Title" />
												</span>
											</xsl:when>
											<xsl:otherwise>
												<span class="title">
													<xsl:value-of select="Title" />
												</span>
											</xsl:otherwise>
										</xsl:choose>
									</xsl:when>
								</xsl:choose>


								<!-- Add a line break - Note: For some reason this tag ends up not 
									being closed in the HTML -->
								<xsl:element name="br"></xsl:element>

								<!-- Display the description which can have mixed content -->
								<xsl:for-each select="Description">
									<xsl:apply-templates />
								</xsl:for-each>

								<!-- Decide whether or not to display the cast list -->
								<xsl:choose>
									<xsl:when test="count(CastList)>0">

										<!-- Add the cast quasi-button -->
										<xsl:element name="span">
											<xsl:attribute name="onclick"> 
                         						<xsl:value-of
												select="concat('toggle(',Series,'Cast);')" /> 
                    						</xsl:attribute>
											[Cast]
										</xsl:element>

										<!-- Add the cast div that will be displayed on button click -->
										<xsl:element name="div">
											<xsl:attribute name="id"> 
                         						<xsl:value-of select="concat(Series,'Cast')" /> 
                    						</xsl:attribute>

											<xsl:attribute name="style"> 
                         						<xsl:value-of select="'display: none;'" /> 
                    						</xsl:attribute>

											<ul class="castlist">

												<xsl:for-each select="CastList">
													<xsl:apply-templates />
												</xsl:for-each>
											</ul>

										</xsl:element>

									</xsl:when>
								</xsl:choose>

							</p>

						</xsl:element>


					</xsl:for-each>

				</xsl:for-each>

				<!-- Create the horizontal links at the top of the page -->
				<p>
					<xsl:apply-templates select="TVGuide/Channel/Name" />
				</p>

			</body>
		</html>
	</xsl:template>

	<!-- Template for channel links -->
	<xsl:template match="TVGuide/Channel/Name">

		<xsl:element name="a">
			<xsl:attribute name="href">#<xsl:value-of select="." /></xsl:attribute>
			<xsl:value-of select="." />
		</xsl:element>
		|
	</xsl:template>

	<!-- Template for characters -->
	<xsl:template match="Character">
		<span class="character">
			<xsl:value-of select="." />
		</span>
	</xsl:template>

	<!-- Template for links -->
	<xsl:template match="Link">
		<xsl:element name="a">
			<xsl:attribute name="href">
				<xsl:value-of select="@href" />
			</xsl:attribute>
			<xsl:apply-templates />
		</xsl:element>

	</xsl:template>

	<!-- Template for cast members -->
	<xsl:template match="CastMember">
		<li>
			<span class="character">
				<xsl:value-of select="Character/Name" />
			</span>
			<xsl:text> </xsl:text>
			<span class="actor">
				<xsl:value-of select="Actor/Name" />
			</span>
		</li>
	</xsl:template>



</xsl:stylesheet>
This article has been dead for over six months. Start a new discussion instead.