Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Max Mumford 266 posts 293 karma points
    Jul 12, 2011 @ 14:05
    Max Mumford
    0

    umbraco.library:FormatDatetime in XSLT template

    Hi all

    I am trying to format a date from the @createDate attribute in my navigation template and I cannot see why it won't let me save the XSLT. Here is the code:

    <xsl:template match="*[@isDoc]">
              <li>
                <href="{umb:NiceUrl(@id)}">
                  <xsl:value-of select="umbraco.library:FormatDateTime('@createDate', 'MMMM')" />
                </a>
                <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)][not((self::uBlogsyFolderMonth | self::umbracoBlogDateFolder | self::DateFolder)[@level = 5])]">
                  <ul>
                    <xsl:apply-templates select="*[@isDoc][not(umbracoNaviHide = 1)][not((self::uBlogsyFolderMonth | self::umbracoBlogDateFolder | self::DateFolder)[@level = 5])]" />
                  </ul>
                </xsl:if>
              </li>
            </xsl:template>

    The error message is:

    Error occured

    Error in XSLT at line 51, char 19
    49:       <xsl:choose>
    50:       <xsl:when test="@level = 4 and (self::uBlogsyFolderMonth | self::umbracoBlogDateFolder | self::DateFolder)">
    51: >>>   <xsl:value-of select="umbraco.library:FormatDateTime('@createDate', 'MMMM')" /> <<<
    52:       </xsl:when>
    53:       <xsl:otherwise> 

    I can change it to just

    <xsl:value-of select="@createDate" />

    and there isnt a problem. I really can't work this one out, I'v tried a hundred different conbinations but it has got to be a single rogue character somewhere...? Any ideas?

    Max.


  • Max Mumford 266 posts 293 karma points
    Jul 12, 2011 @ 14:06
    Max Mumford
    0

    Note: the above code is a trimmed down version, hence the error message showing slightly different code.

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jul 12, 2011 @ 14:06
    Bo Damgaard Mortensen
    0

    Hi Max,

    Have you tried with just 'MM' ? :-) You may have an M too many there.

    Edit: Also, I think you should be able to skip the apostrophes around @createDate :-)

  • Max Mumford 266 posts 293 karma points
    Jul 12, 2011 @ 14:21
    Max Mumford
    0

    Hey, thanks for the reply. I have tried that, even tried 'yyyy'. I also saw the apostrophe's after posting this message but I cannot edit the post but just left it. Removing them dosnt fix it either. 

    <xsl:value-of select="umbraco.library:FormatDateTime(@createDate, 'yyyy')" />

    MMMM is valid - http://en.wikibooks.org/wiki/Umbraco/Reference/umbraco.library/FormatDateTime

    Any other ideas?

  • Max Mumford 266 posts 293 karma points
    Jul 12, 2011 @ 14:46
    Max Mumford
    0

    Another attempt:

    <?xml version="1.0" encoding="utf-8" ?>
    <!DOCTYPE xsl:stylesheet [
            <!ENTITY nbsp "&#x0A;">
    ]>
    <xsl:stylesheet
            version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:umb="urn:umbraco.library"
            exclude-result-prefixes="umb"
    >

            <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

            <xsl:param name="currentPage" />
            <xsl:variable name="level" select="1" />
            
            <xsl:variable name="navRoot" select="$currentPage/ancestor-or-self::*[@level = $level][not(umbracoNaviHide = 1)]" />
            <xsl:variable name="navRootItems" select="$navRoot/*[@isDoc][not(umbracoNaviHide = 1)]" />

            <xsl:template match="/">
              <div class="navtree">
                <table cellspacing="0">
                  <tr>
                    <td id="navleft" />
                    <td id="navcentre">
                      <ul>
                        <li>
                          <xsl:if test="$currentPage/@nodeName = 'Home'"><xsl:attribute name="class">current</xsl:attribute></xsl:if>
                          <href="/">Home</a>
                        </li>
                      </ul>

                      <xsl:if test="$navRootItems">
                        <ul id="treemenu1">
                          <xsl:apply-templates select="$navRootItems" />
                        </ul>
                      </xsl:if>
                    </td>
                    <td id="navright" />
                  </tr>
                </table>
              </div>
            </xsl:template>

            <xsl:template match="*[@isDoc]">
              <li>
                <xsl:if test="@id = $currentPage/@id"><xsl:attribute name="class">current</xsl:attribute></xsl:if>
                <href="{umb:NiceUrl(@id)}">
                  <xsl:choose>
                    <xsl:when test="@level = 4 and (self::uBlogsyFolderMonth | self::umbracoBlogDateFolder | self::DateFolder)">
                     <xsl:call-template name="niceDate">
                       <xsl:with-param name="date" select="@createDate" />
                      </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise
                      <xsl:apply-templates select="@nodeName" />
                    </xsl:otherwise>
                  </xsl:choose>
                </a>
                <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)][not((self::uBlogsyFolderMonth | self::umbracoBlogDateFolder | self::DateFolder)[@level = 5])]">
                  <ul>
                    <xsl:apply-templates select="*[@isDoc][not(umbracoNaviHide = 1)][not((self::uBlogsyFolderMonth | self::umbracoBlogDateFolder | self::DateFolder)[@level = 5])]" />
                  </ul>
                </xsl:if>
              </li>
            </xsl:template>
            
            <xsl:template match="@nodeName[string-length() &gt; 25]">
              <xsl:attribute name="title">
                <xsl:value-of select="." />
              </xsl:attribute>
              <xsl:value-of select="concat(substring(., 1, 24), '&#8230;')" />
            </xsl:template>
      
            <xsl:template name="niceDate">
              <xsl:param name="date" />
              <xsl:value-of select="umbraco.library:FormatDateTime($date, 'MMMM')" />
            </xsl:template>
            
    </xsl:stylesheet>

    Same error.. this has REALLY stumped me. Even when I use

    <xsl:value-of select="Exslt.ExsltDatesAndTimes:formatdate($date, 'd')"/>

    in the above it does the same thing. Even when I paste the whole code into the live version of the website in a new unused xslt file it does not save. even when I hard code the date and put it right at the top of the xslt file next to the html it fails. :/

  • Max Mumford 266 posts 293 karma points
    Jul 12, 2011 @ 14:51
    Max Mumford
    0

    Solved it. Earlier I postd the script on the forums because I was having another problem and when I copied and pasted it back the <xsl:stylesheet> tag attributes were incomplete, i.e. xslt was not loading the required libraries to process the date namespaces. I just copied and pasted the very top declarations of the xslt sheet from the default that umbraco gives with new xslt files and it worked. 

    This is what it should have been:

    <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"
      exclude-result-prefixes="msxml umbraco.library">

    Thanks for the help :)

Please Sign in or register to post replies

Write your reply to:

Draft