Pergunta

I'm editing the itemstyle.xsl to produce my own styling for a Content Query Web Part (CQWP) as follows: (NB - 2 laternative lines of code are shown as (A) and (B)

<xsl:template name="MyNewStyle" match="Row[@Style='MyNewStyle']" mode="itemstyle">
<div class="SipAddress">
  <xsl:value-of select="@SipAddress" />
</div>
<div class="LinkToolTip">
  <xsl:value-of select="@LinkToolTip" />
</div>
<div class="OpenInNewWindow">
  <xsl:value-of select="@OpenInNewWindow" />
</div>
<div class="OnClickForWebRendering">
  <xsl:value-of select="@OnClickForWebRendering" />
</div>
   <div>
   <table width="100%" >
   <tr>
      <td width="45%" ><xsl:value-of select="@Title" /></td>
       <td width="33%"><xsl:value-of select="@Location" /></td>
       (A) <td width="32%"><xsl:value-of select="@EventDate"/></td>
       (B) <td width="32%"><xsl:value-of select="msxsl:format-date(@EventDate, 'dd/mm/yyyy h:mm')"/></td>

   </tr>
  </table>         
  </div>

Using line (A) works in that all the data is all pulled through (I have also edited the CommonViewField in the webpart)

However the date appears in this format: 2011-04-21 10:00:00

So after a bit of googling I came across this: and replaced (A) with (B)

The date field disappeared... (sigh)

What do I need to do to make the date appear in the correct format?

Foi útil?

Solução

After looking for ages for the answer to this I stumbled on it minutes after posting this question...

Anyway, the answer is here: http://blogs.msdn.com/b/joshuag/archive/2009/03/25/custom-date-formats-in-sharepoint-xsl.aspx

Summary:

  1. Reference the ddwrt namespace at the top of the itemstyle.xls xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"

  2. Now you can use the FormatDate function anywhere you like:

    <xsl:template name="Default" match="*" mode="itemstyle">
    <xsl:value-of select="ddwrt:FormatDate(@ArticleStartDate, 2057, 3)"/>
    </xsl:template>

Outras dicas

I found this as the easiest way to limit the date field.

 < xsl:variable name="cDate" select="@cDate"></xsl:variable>

 < xsl:value-of disable-output-escaping="yes" select="substring-before($cDate,' ')"></xsl:value-of>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top