Copied to clipboard

Flag this post as spam?

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


  • Rik Hodiamont 56 posts 156 karma points
    Jun 02, 2015 @ 16:04
    Rik Hodiamont
    0

    Display Custom Datatype values in XSLT

    Hi,

    Is there a way to read the ID's and values of a custom datatype (like a dropdownlist) without using the ID of the datatype but the name of the datatype?

    I use this custom datatype in a document type and read out the value in XSLT.
    For example:

    I have a dropdownlist with the following data:

    ID Value

    1 Test1
    2 Test2
    3 Test3

    In the XSLT I use an if statement and when the contenteditor selects value 'Test1' I need to display some data. 

    In the current case the ID is stored in the database, so the if statement can't be done on 'Test1' but on ID 1.

    Is there a way to read out all the values of the custom datatype so I can store the value in a variable and read that in the if statement?

    Kind regards,

     

    Rik 

     

     

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jun 02, 2015 @ 23:49
    Chriztian Steinmeier
    0

    Hi Rik,

    There's an extension called GetPreValues() (described here) that you may be able to use - not sure if by "custom datatype" you mean completely custom (your own code) or just custom prevalues in a standard datatype. Don't know if this works with the former.

    One thing I usually do, is to create an XML variable of the datatype's values, like this:

    <xsl:variable name="dropdownProxy">
        <val id="1" label="Test 1">Custom text for 1</val>
        <val id="2" label="Test 2">Custom text for 2</val>
        <val id="3" label="Test 3">Custom text for 3</val>
        <!-- etc. -->
    </xsl:variable>
    <xsl:variable name="dropdown" select="msxsl:node-set($dropdownProxy)/val" />
    
    <xsl:variable name="selected" select="$dropdown[@id = $currentPage/selectedProperty]" />
    
    <!-- Now you can do either of these: -->
    <!-- Test by label value -->
    <xsl:if test="$selected/@label = 'Test 1'">
        <!-- Do something -->
    </xsl:if>
    
    <!-- Test by id: -->
    <xsl:if test="$selected/@id = 1">
        <!-- Do something -->
    </xsl:if>
    
    <!-- Or you can simply output the custom value of the selected one -->
    <p>
        <xsl:value-of select="$selected" />
    </p>
    

    Hope that helps,

    /Chriztian

  • Rik Hodiamont 56 posts 156 karma points
    Jun 03, 2015 @ 10:38
    Rik Hodiamont
    0

    Hi Chriztian, 

    Thanks for your answer. It is a standard datatype in Umbraco like a dropdownlist. 

    The problem I'm facing is caused by Courier. When I transfer the custom datatype from stage to production, the ID's of the prevalues change. Therefore the if-statement in the XSLT aren't correct anymore.

    I try to figure out a way to read out how I can have an if statement based on the prevalues  without using the ID's.

    In the current situation, I will do this:

    <xsl:iftest="datatype = 1">
       
    <!-- Do something -->
    </xsl:if>

    1 is the ID for per/mnd.

    In the new situation I want to select based on 'per/mnd' or read out all the values bases on the name of te datatype, which is in this case 'Betaalmethode'.

    I hope this makes more sense. 

    Kind regars,

    Rik 

     

Please Sign in or register to post replies

Write your reply to:

Draft