Copied to clipboard

Flag this post as spam?

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

  • Sander van de Pas 62 posts 122 karma points
    Apr 27, 2012 @ 13:26
    Sander van de Pas

    How to add variable as element

    Dynamically I get the languageCode (e.g. nl or en or us) and put this in a variable. After that I want to use this variable as a property from a media item.

    Instead of $media/umbracoFile I need $media/nl or $media/en or $media/uk depending on the languageCode.

    I tried a lot of things but nothing works.

    Here's my code:

    <xsl:variable name="language" select="$currentPage/ancestor-or-self::Home[@isDoc]" />
    <xsl:variable name="languageCode" select="$language/language" />

    <xsl:for-each select="$currentPage/productDownloads/MultiNodePicker/nodeId">
     <xsl:variable name="media" select="umbraco.library:GetMedia(., false())" />
    <a href="{$media/umbracoFile}" target="_blank">
    <xsl:value-of select="$media/[$languageCode]" />

    Could someone help me?

  • Chriztian Steinmeier 2711 posts 8148 karma points MVP 3x admin c-trib
    Apr 27, 2012 @ 13:32
    Chriztian Steinmeier

    Hi Sander,

    You do that using the name() function:

    <xsl:value-of select="$media/*[name() = $languageCode]" />


  • Sander van de Pas 62 posts 122 karma points
    Apr 27, 2012 @ 14:37
    Sander van de Pas

    Problem was the UPPERCASE of the variable languageCode :-(.

    Now it works!

Please Sign in or register to post replies

Write your reply to: