| |
---|
| | $period_list = sprintf( '"%s"', implode( '", "', array_keys( $periods ) ) ); |
---|
| | |
---|
| | // The period and week variables are defined identically in both templates, so |
---|
| | // let's define them just once here to ensure consistency. |
---|
| | $shared_variables = <<<EOT |
---|
| | <xsl:variable name="period"> |
---|
| | <xsl:choose> |
---|
| | <xsl:when test="{$period_condition}"> |
---|
| | <xsl:value-of select="@period" /> |
---|
| | </xsl:when> |
---|
| | <!-- This also covers the case of @period being undefined. --> |
---|
| | <xsl:otherwise> |
---|
| | $shared_parameters = <<<EOT |
---|
| | <xsl:with-param name="period"> |
---|
| | <xsl:choose> |
---|
| | <xsl:when test="{$period_condition}"> |
---|
| | <xsl:value-of select="@period" /> |
---|
| | </xsl:when> |
---|
| | <!-- This also covers the case of @period being undefined. --> |
---|
| | <xsl:otherwise> |
---|
| | <xsl:message terminate="yes"> |
---|
| | <xsl:text>Attribute "period" must be one of the values {$period_list}.</xsl:text> |
---|
| | </xsl:message> |
---|
| | </xsl:otherwise> |
---|
| | </xsl:choose> |
---|
| | </xsl:with-param> |
---|
| | |
---|
| | <xsl:with-param name="week"> |
---|
| | <xsl:value-of select="@week" /> |
---|
| | <xsl:if test="not( @week )"> |
---|
| | <xsl:message terminate="yes"> |
---|
| | <xsl:text>Attribute "period" must be one of the values {$period_list}.</xsl:text> |
---|
| | <xsl:text>The "week" attribute is required.</xsl:text> |
---|
| | </xsl:message> |
---|
| | </xsl:otherwise> |
---|
| | </xsl:choose> |
---|
| | </xsl:variable> |
---|
| | |
---|
| | <xsl:variable name="week"> |
---|
| | <xsl:value-of select="@week" /> |
---|
| | <xsl:if test="not( @week )"> |
---|
| | <xsl:message terminate="yes"> |
---|
| | <xsl:text>The "week" attribute is required.</xsl:text> |
---|
| | </xsl:message> |
---|
| | </xsl:if> |
---|
| | </xsl:variable> |
---|
| | </xsl:if> |
---|
| | </xsl:with-param> |
---|
| | EOT; |
---|
| | |
---|
| | |
---|
| | // Generate the file header and the wrapper templates. |
---|
| |
---|
| | |
---|
| | <!-- |
---|
| | DO NOT EDIT! Automatically generated by ../generate_calendar_dates.php! |
---|
| | |
---|
| | Elements and functions for generating teaching period dates. Apart from the wrapper templates, this essentially boils down to a giant parameterised lookup table, which is generated by a script. |
---|
| | Elements and templates for generating teaching period dates. Apart from the wrapper templates, this essentially boils down to a giant parameterised lookup table, which is generated by a script. |
---|
| | --> |
---|
| | |
---|
| | |
---|
| | <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
---|
| |
---|
| | @offset: A signed offset specified as an XSLT duration, e.g., "P1D" for plus one day, "-P4D" for minus four days. |
---|
| | --> |
---|
| | <template name="TeachingPeriodDate" match="TeachingPeriodDate"> |
---|
| | <common> |
---|
| | {$shared_variables} |
---|
| | |
---|
| | <xsl:variable name="format"> |
---|
| | <xsl:choose> |
---|
| | <!-- May add some specific simple-date formats here. --> |
---|
| | <xsl:when test="@format = 'day+long-name'"> |
---|
| | <xsl:text>[FNn] [D] [MNn]</xsl:text> |
---|
| | </xsl:when> |
---|
| | <xsl:when test="@format = 'day+short-name'"> |
---|
| | <xsl:text>[FNn,*-3] [D] [MNn]</xsl:text> |
---|
| | </xsl:when> |
---|
| | <xsl:when test="@format = 'day'"> |
---|
| | <xsl:text>[D] [MNn]</xsl:text> |
---|
| | </xsl:when> |
---|
| | <xsl:when test="@format = 'ISO'"> |
---|
| | <xsl:call-template name="format-teaching-date"> |
---|
| | {$shared_parameters} |
---|
| | |
---|
| | <xsl:with-param name="format"> |
---|
| | <xsl:choose> |
---|
| | <!-- Named date formats. --> |
---|
| | <xsl:when test="@format = 'day+long-name'"> |
---|
| | <xsl:text>[FNn] [D] [MNn]</xsl:text> |
---|
| | </xsl:when> |
---|
| | <xsl:when test="@format = 'day+short-name'"> |
---|
| | <xsl:text>[FNn,*-3] [D] [MNn]</xsl:text> |
---|
| | </xsl:when> |
---|
| | <xsl:when test="@format = 'day'"> |
---|
| | <xsl:text>[D] [MNn]</xsl:text> |
---|
| | </xsl:when> |
---|
| | <xsl:when test="@format = 'ISO'"> |
---|
| | <xsl:text>[Y0001]-[M01]-[D01]</xsl:text> |
---|
| | </xsl:when> |
---|
| | <xsl:otherwise> |
---|
| | <xsl:value-of select="@format" /> |
---|
| | </xsl:otherwise> |
---|
| | </xsl:choose> |
---|
| | <xsl:if test="not( @format )"> |
---|
| | <xsl:text>[Y0001]-[M01]-[D01]</xsl:text> |
---|
| | </xsl:when> |
---|
| | <xsl:otherwise> |
---|
| | <xsl:value-of select="@format" /> |
---|
| | </xsl:otherwise> |
---|
| | </xsl:choose> |
---|
| | <xsl:if test="not( @format )"> |
---|
| | <xsl:text>[Y0001]-[M01]-[D01]</xsl:text> |
---|
| | </xsl:if> |
---|
| | </xsl:variable> |
---|
| | |
---|
| | <xsl:variable name="offset"> |
---|
| | <xsl:value-of select="@offset" /> |
---|
| | <xsl:if test="not( @offset )"> |
---|
| | <xsl:text>P0D</xsl:text> |
---|
| | </xsl:if> |
---|
| | </xsl:variable> |
---|
| | |
---|
| | <xsl:value-of select="infosci:format-teaching-date( \$period, \$week, \$format, \$offset )" /> |
---|
| | </xsl:if> |
---|
| | </xsl:with-param> |
---|
| | |
---|
| | <xsl:with-param name="offset"> |
---|
| | <xsl:value-of select="@offset" /> |
---|
| | <xsl:if test="not( @offset )"> |
---|
| | <xsl:text>P0D</xsl:text> |
---|
| | </xsl:if> |
---|
| | </xsl:with-param> |
---|
| | </xsl:call-template> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | |
---|
| |
---|
| | 'false' |
---|
| | --> |
---|
| | <template name="TeachingPeriodDateRange" match="TeachingPeriodDateRange"> |
---|
| | <common> |
---|
| | {$shared_variables} |
---|
| | |
---|
| | <xsl:variable name="month-format"> |
---|
| | <xsl:choose> |
---|
| | <xsl:when test="@format = 'long'"> |
---|
| | <xsl:text>[MNn]</xsl:text> |
---|
| | </xsl:when> |
---|
| | <xsl:when test="@format = 'short'"> |
---|
| | <xsl:text>[MNn,*-3]</xsl:text> |
---|
| | </xsl:when> |
---|
| | <xsl:otherwise> |
---|
| | <xsl:message terminate="yes"> |
---|
| | <xsl:text>Attribute "format" must be either "long" or "short", not "</xsl:text> |
---|
| | <xsl:value-of select="@format" /> |
---|
| | <xsl:text>".</xsl:text> |
---|
| | </xsl:message> |
---|
| | </xsl:otherwise> |
---|
| | </xsl:choose> |
---|
| | </xsl:variable> |
---|
| | |
---|
| | <!-- Convert @wrap into a boolean value. --> |
---|
| | <xsl:variable name="wrap"> |
---|
| | <xsl:value-of select="@wrap = 'yes'" /> |
---|
| | </xsl:variable> |
---|
| | |
---|
| | <xsl:value-of select="infosci:format-teaching-date-range( \$period, \$week, \$month-format, \$wrap )" /> |
---|
| | <xsl:call-template name="format-teaching-date-range"> |
---|
| | {$shared_parameters} |
---|
| | |
---|
| | <xsl:with-param name="month-format"> |
---|
| | <xsl:choose> |
---|
| | <xsl:when test="@format = 'long'"> |
---|
| | <xsl:text>[MNn]</xsl:text> |
---|
| | </xsl:when> |
---|
| | <xsl:when test="@format = 'short'"> |
---|
| | <xsl:text>[MNn,*-3]</xsl:text> |
---|
| | </xsl:when> |
---|
| | <xsl:otherwise> |
---|
| | <xsl:message terminate="yes"> |
---|
| | <xsl:text>Attribute "format" must be either "long" or "short", not "</xsl:text> |
---|
| | <xsl:value-of select="@format" /> |
---|
| | <xsl:text>".</xsl:text> |
---|
| | </xsl:message> |
---|
| | </xsl:otherwise> |
---|
| | </xsl:choose> |
---|
| | </xsl:with-param> |
---|
| | |
---|
| | <!-- Convert @wrap into a boolean value. --> |
---|
| | <xsl:with-param name="wrap"> |
---|
| | <xsl:value-of select="@wrap = 'yes'" /> |
---|
| | </xsl:with-param> |
---|
| | </xsl:call-template> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | |
---|
| | |
---|
| | EOT; |
---|
| | |
---|
| | // Generate the XSLT functions that do all the work. These essentially end up being huge parameterised lookup tables. |
---|
| | generate_function( $first_monday, $periods, 'format-teaching-date' ); |
---|
| | |
---|
| | generate_function( $first_monday, $periods, 'format-teaching-date-range' ); |
---|
| | // Generate the XSLT templates that do all the work. These essentially end up being huge parameterised lookup tables. |
---|
| | generate_template( $first_monday, $periods, 'format-teaching-date' ); |
---|
| | |
---|
| | generate_template( $first_monday, $periods, 'format-teaching-date-range' ); |
---|
| | |
---|
| | |
---|
| | // Footer boilerplate. |
---|
| | print( "</stylesheet>\n" ); |
---|
| |
---|
| | |
---|
| | //////////////////////////////////////////////////////////////////////////////// |
---|
| | |
---|
| | |
---|
| | function generate_function( $first_monday, $periods, $function_name ) |
---|
| | function generate_template( $first_monday, $periods, $template_name ) |
---|
| | { |
---|
| | // A couple of handy date intervals: four days to the end of the current week, |
---|
| | // and seven days to the start of next week. |
---|
| | $plus_four_days = new DateInterval( 'P4D' ); |
---|
| | $plus_seven_days = new DateInterval( 'P7D' ); |
---|
| | |
---|
| | |
---|
| | // Initial boilerplate for the function. |
---|
| | switch ( $function_name ) |
---|
| | // Initial boilerplate for the template. |
---|
| | switch ( $template_name ) |
---|
| | { |
---|
| | case 'format-teaching-date': |
---|
| | print<<<EOT |
---|
| | <!-- |
---|
| | Generate a date (default Monday) for the specified teaching period and week (or break), using the specified date format, with an optional offset from the Monday of the week. Most of the body of this function is automatically generated by the script ../generate_calendar_dates.php. |
---|
| | Generate a date (default Monday) for the specified teaching period and week (or break), using the specified date format, with an optional offset from the Monday of the week. Most of the body of this template is automatically generated by the script ../generate_calendar_dates.php. |
---|
| | |
---|
| | See the attributes of the TeachingPeriodDate template above for descriptions of the parameters. |
---|
| | --> |
---|
| | <function name="infosci:format-teaching-date"> |
---|
| | <template name="format-teaching-date"> |
---|
| | <common> |
---|
| | <xsl:param name="period" as="xs:string" /> |
---|
| | <xsl:param name="week" as="xs:string" /> |
---|
| | <xsl:param name="format" as="xs:string" /> |
---|
| |
---|
| | |
---|
| | case 'format-teaching-date-range': |
---|
| | print<<<EOT |
---|
| | <!-- |
---|
| | Generate a date range for the specified teaching period and week (or break), using the specified month format, with optional wrapping. Most of the body of this function is automatically generated by the script ../generate_calendar_dates.php. |
---|
| | Generate a date range for the specified teaching period and week (or break), using the specified month format, with optional wrapping. Most of the body of this template is automatically generated by the script ../generate_calendar_dates.php. |
---|
| | |
---|
| | See the attributes of the TeachingPeriodDateRange template above for descriptions of the parameters. \$month-format is derived from @format. |
---|
| | --> |
---|
| | <function name="infosci:format-teaching-date-range"> |
---|
| | <template name="format-teaching-date-range"> |
---|
| | <common> |
---|
| | <xsl:param name="period" as="xs:string" /> |
---|
| | <xsl:param name="week" as="xs:string" /> |
---|
| | <xsl:param name="month-format" as="xs:string" /> |
---|
| |
---|
| | EOT; |
---|
| | break; |
---|
| | |
---|
| | default: // WTF?!? |
---|
| | print "Unrecognised function name \"$function_name\", terminating.\n"; |
---|
| | print "Unrecognised template name \"$template_name\", terminating.\n"; |
---|
| | exit; |
---|
| | break; |
---|
| | } // switch function name |
---|
| | } // switch template name |
---|
| | |
---|
| | // Generate XSLT code for each teaching period. |
---|
| | foreach ( $periods as $period_name => $period_data ) |
---|
| | { |
---|
| |
---|
| | sprintf( "P%dD", ( ( $break_week['break_ends'] - $break_week['break_starts'] ) * 7 ) + 4 ) |
---|
| | ) |
---|
| | ); |
---|
| | |
---|
| | switch ( $function_name ) |
---|
| | switch ( $template_name ) |
---|
| | { |
---|
| | case 'format-teaching-date': |
---|
| | generate_date( "B{$num_breaks}", $week_start ); |
---|
| | break; |
---|
| |
---|
| | } // else break start and break end are in different months |
---|
| | break; |
---|
| | |
---|
| | default: // WTF?!? |
---|
| | print "Unrecognised function name \"$function_name\", terminating.\n"; |
---|
| | print "Unrecognised template name \"$template_name\", terminating.\n"; |
---|
| | exit; |
---|
| | break; |
---|
| | } // switch function name |
---|
| | } // switch template name |
---|
| | } // if current week == first week of break |
---|
| | |
---|
| | if ( $week == $break_week['break_ends'] ) |
---|
| | { |
---|
| |
---|
| | else |
---|
| | { |
---|
| | $week_number++; |
---|
| | |
---|
| | switch ( $function_name ) |
---|
| | switch ( $template_name ) |
---|
| | { |
---|
| | case 'format-teaching-date': |
---|
| | generate_date( $week_number, $week_start ); |
---|
| | break; |
---|
| |
---|
| | } // else break start and break end are in different months |
---|
| | break; |
---|
| | |
---|
| | default: // WTF?!? |
---|
| | print "Unrecognised function name \"$function_name\", terminating.\n"; |
---|
| | print "Unrecognised template name \"$template_name\", terminating.\n"; |
---|
| | exit; |
---|
| | break; |
---|
| | } // switch function name |
---|
| | } // switch template name |
---|
| | } // else normal teaching week |
---|
| | |
---|
| | $week_start->add( $plus_seven_days ); |
---|
| | } // for each week |
---|
| |
---|
| | |
---|
| | EOT; |
---|
| | } // foreach teaching period |
---|
| | |
---|
| | // Terminating boilerplate for the function. |
---|
| | // Terminating boilerplate for the template. |
---|
| | print<<<EOT |
---|
| | </xsl:choose> |
---|
| | </common> |
---|
| | </function> |
---|
| | |
---|
| | |
---|
| | |
---|
| | EOT; |
---|
| | } // generate_function |
---|
| | </template> |
---|
| | |
---|
| | |
---|
| | |
---|
| | EOT; |
---|
| | } // generate_template |
---|
| | |
---|
| | |
---|
| | //////////////////////////////////////////////////////////////////////////////// |
---|
| | |
---|
| |
---|
|