Copied to clipboard

Flag this post as spam?

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


  • Nigel Wilson 945 posts 2077 karma points
    Jul 13, 2011 @ 02:04
    Nigel Wilson
    0

    Retrieve variable based on QueryString variable

    Hi there

    I have the following code:

    <xsl:variable name="callCategories" select="string(umbraco.library:RequestQueryString('callCategories'))"/>
    <xsl:variable name="ArticleEnquiry">
            <xsl:text>Coupon Book,Pricing,Promotions</xsl:text>
        </xsl:variable> ...
    <xsl:variable name="WholesaleOperations">
            <xsl:text>Consumables,Ops Other Faults,Reset Gun,Reset User,Restores</xsl:text>
        </xsl:variable>
    <xsl:variable name="selectedCategory">
                <xsl:choose>
                    <xsl:when test="$callCategories = 'ArticleEnquiry'">
                        <xsl:value-of select="$ArticleEnquiry"/>
                    </xsl:when>
    <xsl:when test="$callCategories = 'WholesaleOperations'">
                        <xsl:value-of select="$WholesaleOperations"/>
                    </xsl:when>
                </xsl:choose>
            </xsl:variable>

    The above works fine but is there a better way to assign a value to the variable selectedCategory ?

    The list of options is quite large (reduced here for brevity) and therefore somewhat cumbersome to manage on an ongoing basis if there are changes to the possible call category options.

    I look forward to peoples responses.

    Thanks
    Nigel

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jul 13, 2011 @ 13:29
    Chriztian Steinmeier
    1

    Hi Nigel,

    This is a perfect contender for a pattern I use a lot: I create a "proxy" XML variable with the values needed, create an XPath-navigable variable from it (using the node-set() function) and then select into that variable:

    <xsl:variable name="prevalues-list">
        <values id="ArticleEnquiry">Coupon Book,Pricing,Promotions</values>
        <values id="WholesaleOperations">Consumables,Ops Other Faults,Reset Gun,Reset User,Restores</values>
        <!-- Etc. -->
    </xsl:variable>
    <xsl:variable name="prevalues" select="msxsl:node-set($prevalues-list)" />
    
    <xsl:variable name="callCategories" select="umbraco.library:RequestQueryString('callCategories')" />
    
    <xsl:variable name="selectedCategory" select="$prevalues[@id = $callCategories]" />
    
    This way, you can expand your list of values infinitely, without having to duplicate anything.

    /Chriztian 

  • Nigel Wilson 945 posts 2077 karma points
    Jul 13, 2011 @ 21:51
    Nigel Wilson
    0

    Hi Chriztian

    That is wicked - thank you for taking the time to detail this. 

    Upward and onward...

    Kind regards

    Nigel

Please Sign in or register to post replies

Write your reply to:

Draft