Jump to content

XSLT Time Manipulation


eight968

Recommended Posts

I have the following in XSLT:<xsl:variable name="startTime" select="@startDateTime" /><xsl:variable name="endTime" select="@stopDateTime" /><xsl:variable name="steps" select="@steps" /> I want to create "steps" number of date times that are evenly spaced out between the start and stop times. Basically I want the equivalent to the pseudocode below:<xsl:template match="@location"> <time> <xsl:value-of select="$startTime + (position() * (($endTime - $startTime) / steps))"/> </time></xsl:template>Now I haven't figured out how to do this kind of date manipulation with xslt. Is there even a way to? And if it matters, I'm using Java's jdom 1.0 library to apply this stylesheet.I just stumbled upon xquery-operators that have promise, but if someone does happen to know the answer, that'll be good too.Thanks,Charles

Link to comment
Share on other sites

In XSLT 1.0 you can do that by recursing the XSLT template like this:

<xsl:template name="time" match="/"><xsl:param name="counter" select="0"/><xsl:if test="$counter <= @location"><time> <xsl:value-of select="$startTime + (position() * (($endTime - $startTime) / steps))"/> </time><xsl:apply-templates><xsl:with-param name="counter" select="$counter + 1"/></xsl:apply-templates></xsl:if></xsl:template>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...