Umbraco publishes date in xslt

Various Umbraco Links indicate that Umbraco stores node createDate and updateDate in umbraco.config (if you want to copy the xslt of the Umbraco content conversion).

But I need to be able to display the publication date in xslt transforms.

Now, after developing this in the Umbraco database, cmsContentVersion.VersionDate is the publication date of node, and cmdDocument.updateDate is the last updated date. I can create a trigger that modifies updateDate to match the publication date whenever the publication date changes and use the following xsl:

<xsl:value-of select="umbraco.library:FormatDateTime(@updateDate, 'd MMM yyyy hh:mm')"/> 

But ideally, I don't want to change the basic definitions of Umbraco tables.

I found this link that suggested expanding the node document to publish the release date in C # using:

 public static string ReleaseDate(int nodeId) { Document d = new Document(nodeId); return d.ReleaseDate.ToString(); } 

... but how do I translate this C # to xslt? Overwriting xslt as ascx macros is not an option.

+4
source share
1 answer

You can use the XSLT extension. See this tutorial (http://www.nibble.be/?p=60), but I adapted it here.

  • Put this .NET code in a class called Extensions in the assembly, which is embedded and copied to the bin folder of your umbraco installation. For example, we will place it in MyProject.dll
  • Open the file /config/xsltExtensions.config.
  • Add the following line to the configuration:

     <ext assembly="\bin\MyProject" type="MyProject.Extensions" alias="MyExtensions"></ext> 
  • In xslt add a link to the extension and exclude the prefix:

     <xsl:stylesheet version="1.0″ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:BlogLibrary="urn:MyExtensions" exclude-result-prefixes="msxml umbraco.library MyExtensions"> 
  • Now you can use this method, like any umbraco.library method, for example:

      <xsl:value-of select="MyExtensions:ReleaseDate($myNodeId)" /> 

Hope this helps.

+2
source

All Articles