Foundry: Moved logic for date formating from news.xsl to general template in template-parser.xsl to make it resuable.
git-svn-id: https://svn.libreccm.org/ccm/trunk@2965 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
069a9e0928
commit
0ea8b1a666
|
|
@ -615,6 +615,115 @@
|
|||
</xsl:if>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="foundry:format-date">
|
||||
<xsl:param name="date-elem"/>
|
||||
<xsl:param name="date-format"/>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="$date-format[@lang = $language]">
|
||||
<xsl:apply-templates select="$date-format[@lang = $language]">
|
||||
<xsl:with-param name="date-elem" tunnel="yes" select="$date-elem"/>
|
||||
</xsl:apply-templates>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:apply-templates select="$date-format[@default = 'true']">
|
||||
<xsl:with-param name="date-elem" tunnel="yes" select="$date-elem"/>
|
||||
</xsl:apply-templates>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="date-format/short-date">
|
||||
<xsl:param name="date-elem" tunnel="yes"/>
|
||||
|
||||
<xsl:value-of select="$date-elem/@date"/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="date-format/long-date">
|
||||
<xsl:param name="date-elem" tunnel="yes"/>
|
||||
|
||||
<xsl:value-of select="$date-elem/@longDate"/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="date-format/iso-date">
|
||||
<xsl:param name="date-elem" tunnel="yes"/>
|
||||
|
||||
<xsl:variable name="year" select="$date-elem/@year"/>
|
||||
<xsl:variable name="month-value" select="$date-elem/@month"/>
|
||||
<xsl:variable name="month">
|
||||
<xsl:choose>
|
||||
<xsl:when test="string-length($month-value) < 2">
|
||||
<xsl:value-of select="concat('0', $month-value)"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$month-value"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
<xsl:variable name="day-value" select="$date-elem/@day"/>
|
||||
<xsl:variable name="day">
|
||||
<xsl:choose>
|
||||
<xsl:when test="string-length($day-value) < 2">
|
||||
<xsl:value-of select="concat('0', $day-value)"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$day-value"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:value-of select="concat($year, '-', $month, '-', $day)"/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="date-format/year">
|
||||
<xsl:param name="date-elem" tunnel="yes"/>
|
||||
|
||||
<xsl:variable name="year-value" select="$date-elem/@year"/>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="foundry:boolean(./@short)">
|
||||
<xsl:value-of select="substring($year-value, 3)"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$year-value"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="date-format/month">
|
||||
<xsl:param name="date-elem" tunnel="yes"/>
|
||||
|
||||
<xsl:variable name="month-value" select="$date-elem/@month"/>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="string-length($month-value) < 2 and foundry:boolean(./@zero)">
|
||||
<xsl:value-of select="concat('0', $month-value)"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$month-value"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="date-format/month-name">
|
||||
<xsl:param name="date-elem" tunnel="yes"/>
|
||||
|
||||
<xsl:value-of select="$date-elem/@monthName"/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="date-format/day">
|
||||
<xsl:param name="date-elem" tunnel="yes"/>
|
||||
|
||||
<xsl:variable name="day-value" select="$date-elem/@day"/>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="string-length($day-value) < 2 and foundry:boolean(./@zero)">
|
||||
<xsl:value-of select="concat('0', $day-value)"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$day-value"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
|
|
@ -552,7 +552,7 @@
|
|||
<xsl:value-of select="$contentitem-tree/nav:attribute[@name = $name]"/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
|
||||
</xsl:template>
|
||||
|
||||
|
||||
|
||||
</xsl:stylesheet>
|
||||
|
|
@ -57,251 +57,23 @@
|
|||
</foundry:doc-desc>
|
||||
</foundry:doc>
|
||||
<xsl:template match="/content-item-layout//news-date">
|
||||
<xsl:choose>
|
||||
<xsl:when test="./format[@lang = $language]">
|
||||
<xsl:apply-templates select="./format[@lang = $language]"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:apply-templates select="./format[@default = 'true']"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<foundry:doc section="user" type="template-tag">
|
||||
<foundry:doc-desc>
|
||||
<p>
|
||||
Outputs the news date in the short format as provided in the data tree by CCM.
|
||||
</p>
|
||||
</foundry:doc-desc>
|
||||
</foundry:doc>
|
||||
<xsl:template match="/content-item-layout//news-date/format/format//short-date">
|
||||
<xsl:param name="contentitem-tree" tunnel="yes"/>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="$contentitem-tree/newsDate">
|
||||
<xsl:value-of select="$contentitem-tree/newsDate/@date"/>
|
||||
<xsl:call-template name="foundry:format-date">
|
||||
<xsl:with-param name="date-elem"
|
||||
select="$contentitem-tree/newsDate"/>
|
||||
<xsl:with-param name="date-format" select="./date-format"/>
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<xsl:when test="$contentitem-tree/nav:attribute[@name = 'newsDate']">
|
||||
<xsl:value-of select="$contentitem-tree/nav:attribute[@name = 'newsDate']/@date"/>
|
||||
<xsl:call-template name="foundry:format-date">
|
||||
<xsl:with-param name="date-elem"
|
||||
select="$contentitem-tree/nav:attribute[@name = 'newsDate']"/>
|
||||
<xsl:with-param name="date-format" select="./date-format"/>
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<foundry:doc section="user" type="template-tag">
|
||||
<foundry:doc-desc>
|
||||
<p>
|
||||
Outputs the news date in the long format as provided in the data tree by CCM.
|
||||
</p>
|
||||
</foundry:doc-desc>
|
||||
</foundry:doc>
|
||||
<xsl:template match="/content-item-layout//news-date/format//long-date">
|
||||
<xsl:param name="contentitem-tree" tunnel="yes"/>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="$contentitem-tree/newsDate">
|
||||
<xsl:value-of select="$contentitem-tree/newsDate/@longDate"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$contentitem-tree/nav:attribute[@name = 'newsDate']">
|
||||
<xsl:value-of select="$contentitem-tree/nav:attribute[@name = 'newsDate']/@longDate"/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
|
||||
</xsl:template>
|
||||
|
||||
<foundry:doc section="user" type="template-tag">
|
||||
<foundry:doc-desc>
|
||||
<p>
|
||||
A short hand template to output the news date in ISO8601 style (yyyy-mm-dd).
|
||||
</p>
|
||||
</foundry:doc-desc>
|
||||
</foundry:doc>
|
||||
<xsl:template match="/content-item-layout//news-date/format//iso-date">
|
||||
<xsl:param name="contentitem-tree" tunnel="yes"/>
|
||||
|
||||
<xsl:variable name="year">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$contentitem-tree/newsDate">
|
||||
<xsl:value-of select="$contentitem-tree/newsDate/@year"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$contentitem-tree/nav:attribute[@name = 'newsDate']">
|
||||
<xsl:value-of select="$contentitem-tree/nav:attribute[@name = 'newsDate']/@year"/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:variable name="month">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$contentitem-tree/newsDate">
|
||||
<xsl:value-of select="$contentitem-tree/newsDate/@month"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$contentitem-tree/nav:attribute[@name = 'newsDate']">
|
||||
<xsl:value-of select="$contentitem-tree/nav:attribute[@name = 'newsDate']/@month"/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:variable name="day-value">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$contentitem-tree/newsDate">
|
||||
<xsl:value-of select="$contentitem-tree/newsDate/@day"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$contentitem-tree/nav:attribute[@name = 'newsDate']">
|
||||
<xsl:value-of select="$contentitem-tree/nav:attribute[@name = 'newsDate']/@day"/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:variable name="day">
|
||||
<xsl:choose>
|
||||
<xsl:when test="string-length($day-value) < 2">
|
||||
<xsl:value-of select="concat('0', $day-value)"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$day-value"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:value-of select="concat($year, '-', $month, '-', $day)"/>
|
||||
</xsl:template>
|
||||
|
||||
<foundry:doc section="user" type="template-tag">
|
||||
<foundry:doc-desc>
|
||||
<p>
|
||||
Outputs the year of a news date. If the <code>short</code> attribute is set to
|
||||
<code>true</code> only the last two columns are shown.
|
||||
</p>
|
||||
</foundry:doc-desc>
|
||||
<foundry:doc-attributes>
|
||||
<foundry:doc-attribute name="short">
|
||||
<p>
|
||||
If set to <code>true</code> only the last two digits of the year are shown.
|
||||
</p>
|
||||
</foundry:doc-attribute>
|
||||
</foundry:doc-attributes>
|
||||
</foundry:doc>
|
||||
<xsl:template match="/content-item-layout//news-date/format//year">
|
||||
<xsl:param name="contentitem-tree" tunnel="yes"/>
|
||||
|
||||
<xsl:variable name="year-value">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$contentitem-tree/newsDate">
|
||||
<xsl:value-of select="$contentitem-tree/newsDate/@year"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$contentitem-tree/nav:attribute[@name = 'newsDate']">
|
||||
<xsl:value-of select="$contentitem-tree/nav:attribute[@name = 'newsDate']/@year"/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="./@short = 'true'">
|
||||
<xsl:value-of select="substring($year-value, 3)"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$year-value"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<foundry:doc section="user" type="template-tag">
|
||||
<foundry:doc-desc>
|
||||
<p>
|
||||
Outputs the month part of the news date. If the value has only one digit it is
|
||||
prefixed by a zero by default.
|
||||
</p>
|
||||
</foundry:doc-desc>
|
||||
<foundry:doc-attributes>
|
||||
<foundry:doc-attribute name="zero">
|
||||
<p>
|
||||
If set to <code>false</code> one digit values (months from 1 to 9) are not
|
||||
prefixed with a zero.
|
||||
</p>
|
||||
</foundry:doc-attribute>
|
||||
</foundry:doc-attributes>
|
||||
</foundry:doc>
|
||||
<xsl:template match="/content-item-layout//news-date/format//month">
|
||||
<xsl:param name="contentitem-tree" tunnel="yes"/>
|
||||
|
||||
<xsl:variable name="month-value">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$contentitem-tree/newsDate">
|
||||
<xsl:value-of select="$contentitem-tree/newsDate/@month"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$contentitem-tree/nav:attribute[@name = 'newsDate']">
|
||||
<xsl:value-of select="$contentitem-tree/nav:attribute[@name = 'newsDate']/@month"/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="string-length($month-value) < 2 and ./@zero = 'false'">
|
||||
<xsl:value-of select="$month-value"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="concat('0', $month-value)"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<foundry:doc section="user" type="template-tag">
|
||||
<foundry:doc-desc>
|
||||
<p>
|
||||
Outputs the month name as provided in the data tree by CCM.
|
||||
</p>
|
||||
</foundry:doc-desc>
|
||||
</foundry:doc>
|
||||
<xsl:template match="/content-item-layout//news-date/format//month-name">
|
||||
<xsl:param name="contentitem-tree" tunnel="yes"/>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="$contentitem-tree/newsDate">
|
||||
<xsl:value-of select="$contentitem-tree/newsDate/@monthName"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$contentitem-tree/nav:attribute[@name = 'newsDate']">
|
||||
<xsl:value-of select="$contentitem-tree/nav:attribute[@name = 'newsDate']/@monthName"/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<foundry:doc section="user" type="template-tag">
|
||||
<foundry:doc-desc>
|
||||
<p>
|
||||
Outputs the day part of the news date. If the value has only one digit it is
|
||||
prefixed by a zero by default.
|
||||
</p>
|
||||
</foundry:doc-desc>
|
||||
<foundry:doc-attributes>
|
||||
<foundry:doc-attribute name="zero">
|
||||
<p>
|
||||
If set to <code>false</code> one digit values (days from 1 to 9) are not
|
||||
prefixed with a zero.
|
||||
</p>
|
||||
</foundry:doc-attribute>
|
||||
</foundry:doc-attributes>
|
||||
</foundry:doc>
|
||||
<xsl:template match="/content-item-layout//news-date/format//day">
|
||||
<xsl:param name="contentitem-tree" tunnel="yes"/>
|
||||
|
||||
<xsl:variable name="day-value">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$contentitem-tree/newsDate">
|
||||
<xsl:value-of select="$contentitem-tree/newsDate/@day"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$contentitem-tree/nav:attribute[@name = 'newsDate']">
|
||||
<xsl:value-of select="$contentitem-tree/nav:attribute[@name = 'newsDate']/@day"/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="string-length($day-value) < 2 and ./@zero = 'true'">
|
||||
<xsl:value-of select="concat('0', $day-value)"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$day-value"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ XSLT 2.0 functions.
|
|||
</foundry:doc-desc>
|
||||
</foundry:doc>
|
||||
<xsl:function name="foundry:boolean" as="xs:boolean">
|
||||
<xsl:param name="value" as="xs:string"/>
|
||||
<xsl:param name="value"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$value = 'true'
|
||||
or $value = 'TRUE'
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@
|
|||
|
||||
<div class="news-date">
|
||||
<news-date>
|
||||
<format default="true">
|
||||
<date-format default="true">
|
||||
<iso-date/>
|
||||
</format>
|
||||
<format lang="de">
|
||||
</date-format>
|
||||
<date-format lang="de">
|
||||
<day zero="true"/>.<month zero="true"/>.<year/>
|
||||
</format>
|
||||
</date-format>
|
||||
</news-date>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue