Copied to clipboard

Flag this post as spam?

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


  • Gordon Saxby 1347 posts 1608 karma points
    May 08, 2010 @ 19:13
    Gordon Saxby
    0

    Problem using an array

    after seeing this - http://our.umbraco.org/wiki/reference/xslt/snippets/date---add-'th,-st,-rd,-nd'-extension - I tried to adapt it to my specific use, but it's not working.

    I have the array as above

    <xsl:variable name="endings" select="umbraco.library:Split('st,nd,rd,th,th,th,th,th,th,th,th,th,th,th,th,th,th,th,th,th,st,nd,rd,th,th,th,th,th,th,th,st',',')"/>

    and then my code (just the bit to get the "th" etc) which is in a for-each loop

    <xsl:value-of select="$endings/value[number(./data [@alias = 'CalendarItemDay'])]/text()" />

    but nothing is returned. "CalendarItemDay" is a numeric datatype with values such as 3, 23, etc.

    This line displays the day value correctly

    <xsl:value-of select="./data [@alias = 'CalendarItemDay']"/>

     

    Any ideas?

     

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    May 09, 2010 @ 12:12
    Sebastiaan Janssen
    0

    Strange. Try sticking the CalendarItemDay in a variable first and see if it works like that.

    <xsl:variable name="dayNumber" select="number(./data [@alias = 'CalendarItemDay'])" />

    It might be that the conversion to a number fails at some point, so make sure to try and output the $dayNumber var during debugging as well.

    Another idea if to stick just a number in the value, like:

    <xsl:value-of select="$endings/value[3]/text()" />

    Just to make sure the error is not in the array.

  • Gordon Saxby 1347 posts 1608 karma points
    May 09, 2010 @ 18:53
    Gordon Saxby
    0

    Very strange indeed! Putting the value of "CalendarItemDay" into a variable and using that variable to select the required array item worked!

    The strange thing is, I thought you couldn't reassign a value to a variable once it was declared!? The code is in a for-each loop.

    Anyway, it is working now, thank you.

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    May 11, 2010 @ 10:58
    Sebastiaan Janssen
    0

    It's not reassigned, after each loop the variable is destroyed and recreated. :-) Glad it's fixed!

  • 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