Created
August 24, 2013 21:20
-
-
Save bzerangue/6330475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<data> | |
<events> | |
<event> | |
<title>Recurring Exciting Event</title> | |
<date>2013-01-01</date> | |
<end-date>2013-12-31</end-date> | |
<recurring>yes</recurring> | |
<recurring-number>7</recurring-number> | |
<recurring-type>days</recurring-type> | |
</event> | |
</events> | |
</data> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date"> | |
<xsl:output method="text" indent="yes" omit-xml-declaration="yes"/> | |
<xsl:template match="/"> | |
<xsl:apply-templates select="data/events/event"/> | |
</xsl:template> | |
<xsl:template match="event"> | |
<!-- Initial Start Date Here --> | |
<xsl:value-of select="date"/> | |
<!-- Recurring Dates Here --> | |
<xsl:call-template name="date-recursion"> | |
<xsl:with-param name="repeat" select="recurring-number"/> | |
<xsl:with-param name="start-date" select="date"/> | |
<xsl:with-param name="end-date" select="end-date"/> | |
</xsl:call-template> | |
</xsl:template> | |
<xsl:template name="date-recursion"> | |
<xsl:param name="repeat"/> | |
<xsl:param name="count" select="$repeat"/> | |
<xsl:param name="start-date"/> | |
<xsl:param name="end-date"/> | |
<xsl:param name="date-diff"> | |
<xsl:value-of select="date:difference($start-date,$end-date)"/> | |
</xsl:param> | |
<xsl:if test="$count <= translate($date-diff,'PD','')"> | |
<xsl:text>, </xsl:text> | |
<xsl:value-of select="date:add($start-date,concat('P',$count,'D'))"/> | |
<xsl:call-template name="date-recursion"> | |
<xsl:with-param name="count" select="$count + $repeat"/> | |
</xsl:call-template> | |
</xsl:if> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment