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
    Aug 02, 2013 @ 11:15
    Kate
    0

    Place an background images in my xslt

    Hi

    I'm trying to insert a background image in my xslt file.
    I have a document where it works fine but I can not get it to work here (Umbraco 4.11.8)
    Here is a part of the code:

    <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:param name="currentPage" />
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />

    <!-- Grab all the sections to show -->
    <xsl:variable name="sections" select="$siteRoot/*[@isDoc][not(umbracoNaviHide = 1)]" />

    <xsl:template match="/">

    xxx

    <xsl:if test="number($currentPage/baggrundsbillede)">
    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/baggrundsbillede, 0)" />

    <xsl:if test="$media">
    <xsl:variable name="url" select="$media/umbracoFile" />
    <div style="width:200px;height:200px;background:url({$url}) no-repeat;">Billede skulle gerne være som et baggrundsbillede nu</div>
    </xsl:if>
    </xsl:if>
    </xsl:template>

     

    Hope you can help me :-)

    /Kate

     

     

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 02, 2013 @ 11:33
    Dennis Aaen
    0

    Hi Kate,

    I can remember that I have done something similar on a project a few years ago.
    On this project I used
    <xsl: value-of  select="" /> to print the image

    <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:outputmethod="xml"omit-xml-declaration="yes"/>

       
    <xsl:paramname="currentPage"/>
       
    <xsl:variablename="siteRoot"select="$currentPage/ancestor-or-self::*[@level = 1]"/>

       
    <!-- Grab all the sections to show -->
       
    <xsl:variablename="sections"select="$siteRoot/*[@isDoc][not(umbracoNaviHide = 1)]"/>

       
    <xsl:templatematch="/">
           
          xxx
           
         
    <xsl:iftest="number($currentPage/baggrundsbillede)">
               
    <xsl:variablename="media"select="umbraco.library:GetMedia($currentPage/baggrundsbillede, 0)"/>
           
             
    <xsl:iftest="$media">
                 
    <xsl:variablename="url"select="$media/umbracoFile"/>
                 
    <divstyle="width:200px;height:200px;background-image:url('<xsl:value-of select="$url"/>') no-repeat;">Billede skulle gerne være som et baggrundsbillede nu</div>
             
    </xsl:if>
           
    </xsl:if>
       
    </xsl:template>  

    I hope the switch to <xsl:value-of select="" /> makes the difference.

    /Dennis

  • Kate 267 posts 610 karma points
    Aug 02, 2013 @ 13:49
    Kate
    0

    It did not help.

    I think the problem is here:

    xxx        
    <xsl:if test="number($currentPage/baggrundsbillede) &gt; 0">vvv
    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/baggrundsbillede, 0)" />

    <xsl:if test="$media">
    <xsl:variable name="url" select="$media/umbracoFile" />
    <div style="width:200px;height:200px;background:url({$url}) no-repeat;">Billede skulle gerne være som et baggrundsbillede nu</div>
    </xsl:if>
    </xsl:if>

    It only spit out the xxx and not the vvv in this line

    <xsl:if test="number($currentPage/baggrundsbillede) &gt; 0">

    Does that make any sense to you :-)

     

    /Kate

     

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 02, 2013 @ 13:53
    Dennis Aaen
    0

    Okay what if you try this one.

    <xsl:if test="$currentPage/baggrundsbillede!=''">vvv
             
    <xsl:variable name="media"select="umbraco.library:GetMedia($currentPage/baggrundsbillede, 0)"/>
           
             
    <xsl:if test="$media">
                 
    <xsl:variable name="url"select="$media/umbracoFile"/>
                 
    <div style="width:200px;height:200px;background:url('<xsl:value-ofselect="$url"/>') no-repeat;">Billede skulle gerne være som et baggrundsbillede nu</div>
              </
    xsl:if>
           
    </xsl:if>

    /Dennis

  • Kate 267 posts 610 karma points
    Aug 02, 2013 @ 14:02
    Kate
    0

    Nope, sorry

    Maybe it is better if I send you the full code :-)

    Just give me a moment to clean it up a bit :-)

  • Kate 267 posts 610 karma points
    Aug 02, 2013 @ 14:10
    Kate
    0

    Here it is:

    <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:param name="currentPage" />
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />

    <!-- Grab all the sections to show -->
    <xsl:variable name="sections" select="$siteRoot/*[@isDoc][not(umbracoNaviHide = 1)]" />

    <xsl:template match="/">

    <a href="http://test.dk" target="_blank" class="btnBuy"><img src="images/btnBuy.png" alt="Bye now" /></a>
    <div id="" class="cntNavigation">
    <div class="cntNavAndLogo">
    <a href="/" class="cntLogo"><img src="images/logo.png" alt="Poly-Control"/></a>
    <div style="">
    <div class="rmm">
    <ul>
    <xsl:apply-templates select="$sections" mode="nav" />
    </ul>
    </div>
    </div>
    </div>
    </div>

    <xsl:apply-templates select="$sections" mode="output" />
    </xsl:template>

    <!-- Navigation template -->
    <xsl:template match="*[@isDoc]" mode="nav">
    <li class="test">
    <a href="#{@urlName}">
    <xsl:value-of select="@nodeName" />
    </a>
    </li>
    </xsl:template>

    <xsl:template match="ForsideSektion" mode="output">
    <!-- Output for Forside -->
    <section id="{@urlName}">
    <header>
    <h1><xsl:value-of select="@nodeName" /></h1>
    </header>
    <div class="text">
    <xsl:value-of select="overskriftTilMultisider" disable-output-escaping="yes" />
    </div>
    </section>

    </xsl:template>

    <xsl:template match="Sektion4" mode="output">
    <!-- Output for Sektion 4 content -->
    xxx
    <xsl:if test="number($currentPage/baggrundsbillede) &#62; 0">vvv
    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/baggrundsbillede, 0)" />

    <xsl:if test="$media">
    <xsl:variable name="url" select="$media/umbracoFile" />
    <div style="width:200px;height:200px;background:url('{$url}') no-repeat;">Billede skulle gerne være som et baggrundsbillede nu</div>
    </xsl:if>
    </xsl:if>

    <div id="{@urlName}" class="split" >
    <div class="splitBgImg" style="background:url(images/bg4.jpg) 0 0 no-repeat;">&#160;</div>
    </div>
    <div id="container5" class="container .classContainer5">
    Indhold til sektion 4
    </div>

    </xsl:template>

    </xsl:stylesheet>

     

     

     

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 02, 2013 @ 14:28
    Dennis Aaen
    0

    Hmm know it's a strange question.

    But something could indicate that you are on page, that has an empty
    baggrundsbillede field, be sure that the current page has content in the baggrundsbillede field.

    And you use a media picker as data type of two pick the image on the site. There is nothing that just pops into my eyes, but I can easily have missing something looking
    through your code.

    /Dennis

  • Kate 267 posts 610 karma points
    Aug 02, 2013 @ 14:38
    Kate
    0

    I have checked it so many times. I also thought it was the problem, but unfortunately :-)
    Thank you for your prompt response.
    I must see if I can find another way to solve the problem.
    Thanks for your time

  • Kate 267 posts 610 karma points
    Aug 02, 2013 @ 14:41
    Kate
    0

    okay, I've figured out what the problem is - I think!
    Do you still want to help?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 02, 2013 @ 14:45
    Dennis Aaen
    0

    Yeah Kate, what was the probem. I will love to hear about this way I also learn new things, and I will try my best to help you finding a solution.

  • Kate 267 posts 610 karma points
    Aug 02, 2013 @ 14:50
    Kate
    0

    My site is built with a frontpage where I keep all my document types, so I have a long html page to my site.
    If I'm on my document type "Forside" added property "background image", it works,(it shows the images) but  I need to have different images on each document type I pull into the frontpage, and thereforeI will need to be able to choose image on the document type "Sektion4".

    Does that make sense?

  • Kate 267 posts 610 karma points
    Aug 02, 2013 @ 14:54
    Kate
    1

    I think i got it. I just need to test it an extra time :-)

    xxx        
    <xsl:if test="./baggrundsbillede!=''">vvv
    <xsl:variable name="media" select="umbraco.library:GetMedia(./baggrundsbillede, 0)" />

    <xsl:if test="$media">
    <xsl:variable name="url" select="$media/umbracoFile" />
    <div style="width:200px;height:200px;background:url('{$url}') no-repeat;">Billede skulle gerne være som et baggrundsbillede nu</div>
    </xsl:if>
    </xsl:if>

     


  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 02, 2013 @ 14:55
    Dennis Aaen
    0

    Okay did you any opportunity to post a screenshot that show your content structure, maybe it will be easier to help then.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 02, 2013 @ 14:57
    Dennis Aaen
    0

    Okay Kate, let me know if you have find a working solution.

    /Dennis

  • Kate 267 posts 610 karma points
    Aug 02, 2013 @ 15:10
    Kate
    0

    Her is my content strukture

    And the page "Forside" is the only page on my website. Just like this exampel: http://vaerksted.info

    So what i did was that I chance from this

    <xsl:if test="$currentPage/testBillede!=''"

    to this

    <xsl:if test=./testBillede!=''"

     

    I have made a test and it works fine :-D

    Thanks for your help, you got me on the right track

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 02, 2013 @ 15:16
    Dennis Aaen
    0

    You are very welcome Kate,

    Good that we together came up with a solution. I will be ready to help you another time, with your XSLT, if I can.

    /Dennis

  • Kate 267 posts 610 karma points
    Aug 02, 2013 @ 15:17
    Kate
    0

    Thanks, that would be great :-)

Please Sign in or register to post replies

Write your reply to:

Draft