Xslt/DateFormat

Aus crazylinux.de
Version vom 25. Mai 2009, 09:58 Uhr von Jonathan (Diskussion | Beiträge) (init)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

from http://geekswithblogs.net/workdog/archive/2007/02/08/105858.aspx


Beispiel:

<xsl:template match="item">
  <tr>                     
    <td align="left">
      <li>
        <a href="{link}" target="desktopRSSWin">
<xsl:call-template name="FormatDate">
<xsl:with-param name="DateTime" select="./pubDate" />
</xsl:call-template> <xsl:value-of select="./title"/></a>
        </li></td>
  </tr>
</xsl:template>


<xsl:template name="FormatDate">
<!-- expected date format Thu, 25 Oct 2007 10:47:09 -0400 -->
<xsl:param name="DateTime" />
<!-- new date format 25 October 2007 -->
<xsl:variable name="day-temp">
<xsl:value-of select="substring-after($DateTime,', ')" />
</xsl:variable>
<xsl:variable name="day">
<xsl:value-of select="substring-before($day-temp,' ')" />
</xsl:variable>
<xsl:variable name="mo-temp">
<xsl:value-of select="substring-after($day-temp,' ')" />
</xsl:variable>
<xsl:variable name="mo">
<xsl:value-of select="substring-before($mo-temp,' ')" />
</xsl:variable>
<xsl:variable name="year-temp">
<xsl:value-of select="substring-after($mo-temp,' ')" />
</xsl:variable>
<xsl:variable name="year">
<xsl:value-of select="substring-before($year-temp,' ')" />
</xsl:variable>
<xsl:value-of select="'[ '"/>
<xsl:if test="(string-length($day) < 2)">
<xsl:value-of select="0"/>
</xsl:if>
<xsl:value-of select="$day"/>
<xsl:value-of select="' '"/>
<xsl:choose>
<xsl:when test="$mo = 'jan' or $mo = 'Jan'">January</xsl:when>
<xsl:when test="$mo = 'feb' or $mo = 'Feb'">February</xsl:when>
<xsl:when test="$mo = 'mar' or $mo = 'Mar'">March</xsl:when>
<xsl:when test="$mo = 'apr' or $mo = 'Apr'">April</xsl:when>
<xsl:when test="$mo = 'may' or $mo = 'May'">May</xsl:when>
<xsl:when test="$mo = 'jun' or $mo = 'Jun'">June</xsl:when>
<xsl:when test="$mo = 'jul' or $mo = 'Jul'">July</xsl:when>
<xsl:when test="$mo = 'aug' or $mo = 'Aug'">August</xsl:when>
<xsl:when test="$mo = 'sep' or $mo = 'Sep'">September</xsl:when>
<xsl:when test="$mo = 'oct' or $mo = 'Oct'">October</xsl:when>
<xsl:when test="$mo = 'nov' or $mo = 'Nov'">November</xsl:when>
<xsl:when test="$mo = 'dec' or $mo = 'Dec'">December</xsl:when>
</xsl:choose>
<xsl:value-of select="' '"/>
<xsl:value-of select="$year"/>
<xsl:value-of select="' ] '"/>
</xsl:template>