Copied to clipboard

Flag this post as spam?

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


  • Nathan McGuirk 7 posts 27 karma points
    Jul 18, 2013 @ 14:44
    Nathan McGuirk
    0

    XSLT variables and umbraco.library

    Hi All,

    I hope this is a really simple one, but I'm very new to XSLT and for me unexpected syntax is what actually works when doing xslt work.

    I want to assign a variable, and depending on conditions assign a value from umbraco.library. If it were anything else, I would write it as such:

    <xsl:variable name="media">
    <xsl:if test="xyz != ''">
    <xsl:value-of select="xyz" />
    </xsl:if>
    </xsl:variable>

    Unfortunately I can't seem to get this when I want to call from something in umbraco library. E.G. this does not work:

    <xsl:variable name="media">
    <xsl:if test="logoFile != ''">
    <xsl:value-of select="umbraco.library:GetMedia(logoFile, 0)" />
    </xsl:if>
    </xsl:variable>

    But what I can get to work (and what doesn't work for the structure of the display) is:

    <xsl:if test="logoFile != ''">
    <xsl:variable name="media select="umbraco.library:GetMedia(logoFile, 0)" />
    </xsl:if> <!-- Doesn't allow me to re-use $media elsewhere -->

    If I could get the second option to work some how, a lot of dynamic content building would go smoothly.

     

    Thank you for your time reading my inquiry.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 18, 2013 @ 15:22
    Dennis Aaen
    0

    Hi Nathan,

    If I understand your question correctly, then you are trying to print out an image from a media picker data type with an alias of logoFile. If so, this XSLT should print out the image.

    <xsl:variablename="media"select="umbraco.library:GetMedia($currentPage/logoFile, 0/umbracoFile)"/>
    <xsl:variable name="alt" select="umbraco.library:GetMedia($currentPage/logoFile, 0)/@nodeName" />
    <xsl:iftest="$media !=''">
       
    <imgsrc="{$media}" alt="($alt)"/>
     
    </xsl:if>

    I hope this can help you in some way.

    /Dennis

  • Nathan McGuirk 7 posts 27 karma points
    Jul 18, 2013 @ 16:37
    Nathan McGuirk
    0

    Hi Dennis,

    Yes, for the most part that would work but I see now I forgot to add one important item, the image is not always necessarily present. So for pages that have a logoFile it will display the nodes, but it will return a parse error if there isn't any.

    This is an item that may or may not be present, and may be in one or many places depending on the determination of the content editor

Please Sign in or register to post replies

Write your reply to:

Draft