Copied to clipboard

Flag this post as spam?

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


  • Andy 4 posts 22 karma points
    Jul 11, 2009 @ 16:15
    Andy
    1

    getting the text from a dropdown data type

    hello all,

     

    Sorry about the post I am sure it is a fairly simple question but I have a dropdown datatype called ProductRange when I display ProductRange currently I get the value in the form of an id and I want to retrieve the text.

     

    I know its something to do with GetPreValueAsString() but can't get the syntax right:

     

    <xsl:variable name="prodRangeId" select="data [@alias = 'ProductRange']"/>
    test: <xsl:value-of select="umbraco.library:GetPreValueAsString($prodRangeId)"/>

     

    Does anyone know where I am going wrong? Is this the best way to get the text from a dropdown datatype?

     

    Sorry for the basic questions.

     

    Thanks

    Andy

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 11, 2009 @ 16:54
    Dirk De Grave
    0

    Hi Andy,

    Code snippet sounds perfect, it's how you need to do it. Just for testing purposes, try to set a known value rather than using a variable, and see if it works like that...

    test: <xsl:value-of select="umbraco.library:GetPreValueAsString(1234)"/>

    (Replace 1234 with the id of the item in the dropdown - Can get that value if you go back to the datatype in the Developer section).

    Let us know what you find out.

     

    Cheers,

    /Dirk

     

     

  • Andy 4 posts 22 karma points
    Jul 11, 2009 @ 17:50
    Andy
    0

    Hiya Dirk,

     

    Thanks again for your help: if I use say

    test: <xsl:value-of select="umbraco.library:GetPreValueAsString('52')"/>

    it works fine but if I use the follow syntax:

    <xsl:variable name="prodRangeId" select="data [@alias = 'ProductRange']"/>
    test: <xsl:value-of select="umbraco.library:GetPreValueAsString($prodRangeId)"/>

    I get this error:

    System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    at System.Double.System.IConvertible.ToInt32(IFormatProvider provider)

    Is this because because a string is being pulled? Can you convert item into Int32 with the XSLT?

    Thanks again,

    Andy

     

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 11, 2009 @ 19:23
    Dirk De Grave
    0

    No, it means that the var prodRangeId probably doesn't have a value at run-time.

    Add an extra statement:

    <xsl:text>*</xsl:text><xsl:copy-of select="$prodRangeId" /><xsl:text>*</xsl:text>

    to find out whether prodRangeId has a value at run time.

    If saving your xslt, you will get that error you mention as the prodRangeId doesn't have a value at design-time, resulting in an overflow as the xslt is being compiled/checked against a node (which may/may not have that property - and if it has - doesn't have a value until runtime)

     

    Let us know what you get as output.

     

    Cheers,

    /Dirk

     

     

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Jul 11, 2009 @ 23:38
    Peter Dijksterhuis
    0

    You *could* check the tickbox to skip testing when saving. (the value isn't present when you save, hence the error)

    Alternatively, you could do an xsl:if around it to check if the value is empty or not.

    HTH,

    PeterD

  • Benoit 14 posts 34 karma points
    Jan 30, 2010 @ 20:51
    Benoit
    0

    Hello all,

     

    I have started using Umbraco a couple of days ago, and creating my first little project

    i am having exactly the same issue here, and it seems that the exact problem has been pinpointed by Dirk.

    Writing this gives me a number

    <xsl:value-of select="$currentPage/data [@alias='Rubriek']"/>

     

    i.e.14

    Writing this throws an overflowexception

    <xsl:variable name="rubriekID" select="$currentPage/data [@alias='Rubriek']"/>
    <xsl:copy-of select="umbraco.library:GetPreValueAsString(rubriekID)" /> 

    While writing this gives me the correct result

    <xsl:copy-of select="umbraco.library:GetPreValueAsString(14)" /> 

    Leaves me with the question what do I do about it ?

    Thanks

  • Torben Jensen 13 posts 35 karma points
    Dec 23, 2010 @ 13:25
    Torben Jensen
    0

    @Benoit:


    I had exactly the same issue, but as you can see from above, it's just because the value is not assigned at design time. Yes, XSLT is extremely picky about certain things... we just have to live with it.

    Solution was to put an if clause around, like:

    <xsl:if test="$currentPage/data [@alias='Rubriek'] &gt; 0">
    <xsl:copy-of select="umbraco.library:GetPreValueAsString($currentPage/data [@alias='Rubriek']
    )" />
    </xsl:if>

     

Please Sign in or register to post replies

Write your reply to:

Draft