Copied to clipboard

Flag this post as spam?

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


  • Kate 267 posts 610 karma points
    Nov 07, 2012 @ 10:34
    Kate
    0

    insert a background image in a a-tag

    Hi

    I have a problem whit an background images that dosen't come out right. Im trying to put a Style into a <a> in my Xslt file. but something goes wrong whit the path to the background images.

    In the Macro I have set the Parameters like this:

    I have an xslt file containing this:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:variable name="temp" select="string(/macro/urlNumber)"/>
    <xsl:variable name="class" select="string(/macro/className)"/>
    <xsl:variable name="text" select="string(/macro/tagText)"/>
    <xsl:variable name="bgImg" select="string(/macro/bgImage)"/>
    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:choose>
    <xsl:when test="$class != '' and $text != '' and $temp != ''">
    <a href="{umbraco.library:NiceUrl($temp)}" class="{$class}" style="background:url({$bgImg}) no-repeat;">
    <xsl:value-of select="$text" disable-output-escaping="yes"/>
    </a>
    </xsl:when>
    <xsl:when test="$temp != ''">
    <xsl:value-of select="umbraco.library:NiceUrl($temp)"/>
    </xsl:when>
    </xsl:choose>
    </xsl:template>

    </xsl:stylesheet>

    and the output on the page is this:

    <a style="background:url(/media/8/iconData2.png72372409png) no-repeat;" class="readmore" href="/tekst-side/underside.aspx">se her</a>

    What am I doing wrong?

     

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Nov 07, 2012 @ 10:40
    Chriztian Steinmeier
    2

    Hi Kate,

    The "mediaCurrent" parameter gives you an XML chunk, so you need to specifically select the umbracoFile element inside it:

    <xsl:variable name="temp" select="/macro/urlNumber"/>
    <xsl:variable name="class" select="/macro/className"/>
    <xsl:variable name="text" select="/macro/tagText"/>
    <xsl:variable name="bgImg" select="/macro/bgImage/*/umbracoFile"/>

    (And you don't need the string() thing, though it doesn't hurt anyone :-)

    /Chriztian

  • Kate 267 posts 610 karma points
    Nov 07, 2012 @ 10:48
    Kate
    0

    It works perfect :-)

    Thank you very much

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Nov 07, 2012 @ 10:55
    Chriztian Steinmeier
    0

    You're welcome - and might I add, a perfect example of how to ask a question :-)

    /Chriztian

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies