Copied to clipboard

Flag this post as spam?

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


  • Bambe 45 posts 66 karma points
    Mar 29, 2011 @ 10:36
    Bambe
    0

    the function of many days in a month

    Here have a function to calculate the months days?

    e.g 2011/2 = 28 days, 2012/2 = 29 days or 2010/4 = 30 days etc...

    thx alot :)


    Regards,

    Bambe

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 29, 2011 @ 12:00
    Jan Skovgaard
    0

    Hi Bambe

    I'm not sure this can be done in XSLT. I guess you would need to create an extension to return the number of days in a given month. Probably not something that is hard to do if you have the proper .NET/C# skills.

    Don't know if this kind of extension exists in uComponents though.

    /Jan

  • Pasang Tamang 258 posts 458 karma points
    Mar 29, 2011 @ 12:17
    Pasang Tamang
    1

    Hi Bambe,

    May be this will help you

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:GetDays="urn:GetDays"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <!-- start writing XSLT -->
    <xsl:value-of select="GetDays:GetDaysCount(2010,2)"/>
    </xsl:template>
    <msxml:script language="C#" implements-prefix="GetDays">
        <msxml:using namespace="system" />
        public static string GetDaysCount(int year, int month)
        {
    var dayCount=DateTime.DaysInMonth(year, month);
         return dayCount.ToString();
        }
      </msxml:script>
    </xsl:stylesheet>

    Pnima

  • Bambe 45 posts 66 karma points
    Mar 29, 2011 @ 15:28
    Bambe
    0

    Hi, Pasang

    Thanks for your solution :)

  • Bambe 45 posts 66 karma points
    Mar 29, 2011 @ 16:17
    Bambe
    0

    Hi, Pasang

    Sorry have a problem

    I use the GetDays:GetDaysCount() function and insert two variable to it like this: GetDays:GetDaysCount($year,$month)

    and save then but tell something: System.OverflowException: Value was either too large or too small for an Int32

    here is my code...

    <xsl:variable name="monthend">
      <xsl:variable name="qryyear" select="umbraco.library:RequestQueryString('y')"/>
      <xsl:variable name="qrymonth" select="umbraco.library:RequestQueryString('m')"/>
      <xsl:value-of select="GetDays:GetDaysCount($qryyear,$qrymonth)"/>
    </xsl:variable>

    how can I solve it ? thx :)

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Mar 29, 2011 @ 16:29
    Michael Latouche
    0

    Hi Bambe,

    Did you check that your two variables are actually filled in with a value that is not empty and castable to an int? This error can happen if you pass e.g. an empty string to the method.

    Cheers,

    Michael.

  • Bambe 45 posts 66 karma points
    Mar 29, 2011 @ 17:12
    Bambe
    0

    Hi Michael,

    I'm sure here have a value

    but when I press save button in xslt editor then says the error message

    so how can I do :(

    thx alot :)

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 29, 2011 @ 22:27
    Jan Skovgaard
    0

    Hi Bambe

    What happens if you simply just check "Skip error testing"? Does it fail in the frontend then or is it working?

    /Jan

  • Bambe 45 posts 66 karma points
    Mar 30, 2011 @ 03:34
    Bambe
    0

    Hi Jan,

    it's saying 'Error parsing XSLT file: \xslt\EventList.xslt'

    :(

  • Pasang Tamang 258 posts 458 karma points
    Mar 30, 2011 @ 03:55
    Pasang Tamang
    0

    Hi Bambe,

    Sorry I am late for your answer, just wake up and check your post. In your xslt you forgot to check either qryyear and qrymonth contains value of not. Here is solution

    <xsl:if test="$qryyear!='' or $qrymonth!=''">
      <xsl:value-of select="GetDays:GetDaysCount($qryyear,$qrymonth)"/>
    </xsl:if>

    I've tested this in mine also and error is gone

    Hope this helps you

    Pnima

  • Bambe 45 posts 66 karma points
    Mar 30, 2011 @ 04:17
    Bambe
    0

    Hi Pasang,

    that's amazing! :P

    the solution are fully solved my problem

    Thank you very much :)

     

    Regards,

    Bambe :)

     

     

  • Pasang Tamang 258 posts 458 karma points
    Mar 30, 2011 @ 05:28
    Pasang Tamang
    0

    You are most welocme Bambe. Glad to hear you did solved you problem.

    Pnima

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Mar 30, 2011 @ 09:53
    Michael Latouche
    0

    Hi Bambe,

    Can you maybe mark Pasang's previous post as answer to your question? This can help other people who might have similar issues in finding a solution. Thanks!

    Cheers,

    Michael.

  • Bambe 45 posts 66 karma points
    Mar 30, 2011 @ 10:07
    Bambe
    0

    Hi Michael,

    hmm..

    I had already marked the answer yesterday :P

    have you seen it??

     

    Regards,

    Bambe :)

     

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Mar 30, 2011 @ 10:20
    Michael Latouche
    0

    Woops...

    Did not pay enough attention this morning apparently. I guess I need some more coffee :-)

    Cheers,

    Michael.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 30, 2011 @ 14:36
    Jan Skovgaard
    0

    Hi guys

    I'm glad to see this issue has been resolved.

    However it's not always a good idea or a best practice to use inline C# inside XSLT files. Prefferably one should make an extension, which could take the needed parameters.

    Just saying this so people don't get wrong habbits. Sometimes it's at a lower scale where it does not matter that much and you really just need to be pragmatic. But once you work on a larger project something like this could hurt performance :-)

    /Jan

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies