Created
August 24, 2013 21:12
-
-
Save bzerangue/6330443 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"> | |
<xsl:value-of select="date"/> | |
<xsl:call-template name="date-recursion"/> | |
</xsl:template> | |
<!-- Entering in static values, not using the XML yet, this works when you look at the result --> | |
<xsl:template name="date-recursion"> | |
<xsl:param name="repeat" select="7"/> | |
<xsl:param name="count" select="$repeat"/> | |
<xsl:param name="start-date" select="'2013-01-01'"/> | |
<xsl:param name="end-date" select="'2013-12-31'" /> | |
<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