Copied to clipboard

Flag this post as spam?

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


  • Robin Hansen 135 posts 368 karma points
    Jun 04, 2013 @ 10:41
    Robin Hansen
    0

    DateGreaterThanOrEqual - simply won't compare

    I'm trying to compare some dates in order to display only publiced articles - but honestly, I'm going slightly mad very soon... - no matter what I keep getting the very same error:

    Error parsing the XSLT:

    System.Xml.Xsl.XslTransformException: An error occurred during a call to extension function 'DateGreaterThanOrEqual'. See InnerException for a complete description of the error. ---> System.FormatException: String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s) at umbraco.library.DateGreaterThanOrEqual(String firstDate, String secondDate) --- End of inner exception stack trace --- at System.Xml.Xsl.Runtime.XmlExtensionFunction.Invoke(Object extObj, Object[] args) at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args) at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results) at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt, Dictionary`2 parameters) at umbraco.presentation.umbraco.developer.Xslt.xsltVisualize.visualizeDo_Click(Object sender, EventArgs e)

    this is my code:

    <xsl:variable name="datenow" select="umbraco.library:CurrentDate()" />
        <xsl:for-each select="$currentPage/descendant::* [local-name() = 'Artikel' and @isDoc and string(umbracoNaviHide) != '1' and umbraco.library:DateGreaterThanOrEqual($datenow,publishdate)]">
            <xsl:value-of select="@nodeName"/>: <xsl:value-of select="publishdate" /><br/>
        </xsl:for-each>

    what's supposed to be a walk in the park has now caused me two(2) days of hair pulling frustrations... :(

    I use umbraco v 4.7.1.1 (Assembly version: 1.0.4393.24044) by the way... :-|

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jun 04, 2013 @ 10:58
    Chriztian Steinmeier
    100

     

    Hi Robin,

    First of all: The error means that one of the values is not a date value (but of course you know that). The thing is that you can get this error very easily when using for-each to grab a lot of nodes - in your case, if just a single Artikel node below $currentPage has an empty publishdate property, this will fail.

    Try this to debug:

    <xsl:variable name="datenow" select="umbraco.library:CurrentDate()" />
    
    <!-- Artikel nodes that are visible -->
    <xsl:variable name="nodes" select="$currentPage//Artikel[not(umbracoNaviHide = 1)]" />
    
    <!-- Any of those with empty publishdate ? -->
    <xsl:variable name="nodesWithNoPublishDate" select="$nodes[not(normalize-space(publishdate))]" />
    
    <!-- Grab the ones that are OK -->
    <xsl:variable name="nodesWithPublishDate" select="$nodes[normalize-space(publishdate)]" />
    
    <!-- Show the wrong ones, if any -->
    <xsl:for-each select="$nodesWithNoPublishDate">
        <p>
            <xsl:value-of select="concat(@nodeName, ' (ID: ', @id, ')')" />
        </p>
    </xsl:for-each>
    
    <!-- Show the OK ones that have a publishdate today or in the past -->
    <xsl:for-each select="$nodesWithPublishDate[umbraco.library:DateGreaterThanOrEqual($datenow, publishdate)]">
        <p>
            <xsl:value-of select="concat(@nodeName, ': ', publishdate)" />
        </p>
    </xsl:for-each>

    With many of the library extensions it's important to only call them with valid values, e.g. NiceUrl() and GetXmlNodeById() horribly dies on values that aren't IDs.

    Hope this helps,

    /Chriztian

     

  • Robin Hansen 135 posts 368 karma points
    Jun 10, 2013 @ 10:09
    Robin Hansen
    0

    Hi Chriztian,

    Sry for this late reply - but you nailed it spot on... - thank you so mutch... - exactly what I needed... :-)

    Tnx again m8

    :-)

Please Sign in or register to post replies

Write your reply to:

Draft