Copied to clipboard

Flag this post as spam?

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


  • Mehtab Malik 21 posts 70 karma points
    Jul 07, 2013 @ 10:09
    Mehtab Malik
    0

    umbraco macro XSLT not working

     get an image folder parameter (folder present in the media section) from macro in Umbraco and then loop through the all the images. First thing I check that folder is not empty and then during the loop I further try to check if an image name is equal to "marhall_spadayhpbanner_jul131%20(4).jpg" then I need to put a different link to anchor. I have tried the following xslt code but for some reason its not working as expected and the second condition (when image equal to 'media/42595/marhall_spadayhpbanner_jul131%20(4).jpg' ) is never true.

     

    <xsl:for-each select="$imageFolderContents/node [@nodeTypeAlias='Image']">
        <xsl:if test="string(current()/data [@alias='umbracoFile']) != ''">
            <a href="www.somelink.com">
                <img alt="{current()/@nodeName}">
                    <xsl:attribute name="src"><xsl:value-of select="current()/data [@alias='umbracoFile']"/></xsl:attribute>
                </img>
            </a>
        </xsl:if>
        <xsl:if test="string(current()/data [@alias='umbracoFile']) = 'media/42595/marhall_spadayhpbanner_jul131%20(4).jpg'">
            <a href="someotherlink.com">
                <img alt="{current()/@nodeName}">
                    <xsl:attribute name="src"><xsl:value-of select="current()/data [@alias='umbracoFile']"/></xsl:attribute>
                </img>
            </a>
        </xsl:if>
    </xsl:for-each>
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 07, 2013 @ 10:55
    Jan Skovgaard
    0

    Hi Methab

    What version of Umbraco are you using? The above example is using the old XML schema, which was changed in Umbraco 4.5 so if you're using a newer version of Umbraco that's why the above does not work and we need to refactor it.

    /Jan

  • Mehtab Malik 21 posts 70 karma points
    Jul 07, 2013 @ 11:35
    Mehtab Malik
    0

    thanks for the reply Jan. I m using and old version of umbraco 4.0.3. 

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 08, 2013 @ 01:21
    Chriztian Steinmeier
    100

    Hi Mehtab,

    It probably didn't work because the umbracoFile property will output an absolute path (starting with a slash).

    You should be able to just do this - I assumed you didn't want the link + image twice, in case of a match:

    <xsl:for-each select="$imageFolderContents/node[@nodeTypeAlias = 'Image']">
        <xsl:variable name="filePath" select="data[@alias = 'umbracoFile']" />
        <xsl:if test="normalize-space($filePath)">
            <a href="http://www.somelink.com">
                <!-- Change the link if this is a specific file -->
                <xsl:if test="$filePath = '/media/42595/marhall_spadayhpbanner_jul131%20(4).jpg'">
                    <xsl:attribute name="href">http://www.someothersite.com</xsl:attribute>;
                </xsl:if>
                <img src="{$filePath}" alt="@nodeName}" />
            </a>
        </xsl:if>
    </xsl:for-each>

    /Chriztian 

Please Sign in or register to post replies

Write your reply to:

Draft