Copied to clipboard

Flag this post as spam?

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


  • Andrew 11 posts 32 karma points
    Oct 26, 2011 @ 12:54
    Andrew
    0

    select parameter causing errors

    I want to display an image from a media picker, my document type has several media pickers defined and I would like to use the same macro to dislplay the image for each one. I have a macro parameter for alias called propertyAlias which I use to pass in the name of the media picker. But the xslt does not like the variable being used, see:  Unexpected token '$' in the expression what am I doing wrong please?

     

        <xsl:param name="currentPage"/>
        <xsl:variable name="propertyAlias" select="//macro/propertyAlias" />
      
        <xsl:template match="/">
        
          <xsl:value-of select="$propertyAlias"/>

            <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/$propertyAlias, 0)/umbracoFile" />
            <xsl:if test="$media">
           
                <img src="{$media}"  />
           
             </xsl:if>
        

          </xsl:template> 

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 26, 2011 @ 13:18
    Fuji Kusaka
    0

    Hi Andrew,

     

    May be this will help you, i havent tested it but i think it should get you workin

    <xsl:param name="currentPage"/>
        <xsl:variable name="propertyAlias" select="macro/propertyAlias" />
      
        <xsl:template match="/">
             <xsl:apply-templates select="$currentPage/TestImg" />

       
    </xsl:template>


    <xsl:template match="TestImg">
            <xsl:variable name="media" select="umbraco.library:GetMedia(., false())" />
            <xsl:if test="$propertyAlias">
                    <img src="{$media}"/>
            </xsl:if>
    </xsl:template>

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Oct 26, 2011 @ 14:11
    Tom Fulton
    1

    Hi,

    To fix that error you should remove the second $ sign from $currentPage/$propertyAlias

    If you want to use a variable field name, you can do:

    $currentPage/* [not(@isDoc)][name() = $propertyAlias]

    Also, if you get more errors (value too small...) you might need to wrap the GetMedia call in a test to make sure you have a value, ie:

    <xsl:if test="$currentPage/* [not(@isDoc)][name() = $propertyAlias] &gt; 0">
    ....
    </xsl:if>

    -Tom

Please Sign in or register to post replies

Write your reply to:

Draft