Domanda

I am editing the dispform.aspx in SharePoint Designer 2010, as to not show the created by fields in the announcement lists. I notice that the expire ([Expires]) date field is off. Example:

I have an expire date of 2/3/2012 but shows as 2012-02-03T04:00:00Z

<xsl:with-param name="dateValue" select="@Expires" />

È stato utile?

Soluzione

Unfortunately, XSLT/XPath 1.0 have no date manipulation functions (unless you count something like EXSLT's "Dates and Times" function, which I try not to, as these extension functions aren't always present).

If the source and result formats are going to remain fixed, you can do some basic (although ugly) string composition to accomplish what you want. In particular, this XPath:

concat(
  format-number(substring(., 6, 2), '0'),
  '/',
  format-number(substring(., 9, 2), '0'),
  '/',
  substring(., 1, 4)
)

...should do the trick.

When this XSLT-based verification:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output omit-xml-declaration="no" indent="yes" method="text"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="/*">
     <xsl:value-of
       select="concat(
                 format-number(substring(., 6, 2), '0'),
                 '/',
                 format-number(substring(., 9, 2), '0'),
                 '/',
                 substring(., 1, 4)
               )" />
  </xsl:template>

</xsl:stylesheet>

...is applied against this proposed XML:

<t>2012-02-03T04:00:00Z</t>

...the wanted result is produced:

2/3/2012
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top