Copied to clipboard

Flag this post as spam?

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


  • Bas Schouten 135 posts 233 karma points
    Mar 23, 2010 @ 11:19
    Bas Schouten
    0

    & Character in output

    I want to use an image from Imagegen in a stylesheet.

    I use this code:

    <xsl:variable name="gen">
    <xsl:text disable-output-escaping="yes"><![CDATA[&test]]></xsl:text>
    </xsl:variable>

    <div  style="width:367px; height:247px; background-image:url(/umbraco/ImageGen.ashx?image={./data[@alias = 'umbracoFile']}{$gen})">test</div>

    This will output:

    <div style="width:367px; height:247px; background-image:url(/umbraco/ImageGen.ashx?image=/media/538/img2.jpg&amp;test)">test</div>

    Is there a way to convert the &amp; to a normal &

    Thanx

     

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Mar 23, 2010 @ 12:41
    Jan Skovgaard
    0

    Hi Bas

    Would'nt it be solved if you write your variable like this:

    <xsl:variable name="gen">&amp;<xsl:text disable-output-escaping="yes"><![CDATA[test]]></xsl:text> </xsl:variable>

    /Jan

  • Bas Schouten 135 posts 233 karma points
    Mar 23, 2010 @ 13:38
    Bas Schouten
    0

    Hi Jan,

    It is not the solution. It still outputs the &amp;

    This is the full source:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
     <!ENTITY nbsp "&#x00A0;">
     
    <!ENTITY amp "<![CDATA[&amp;amp;]]>">
    ]>
    <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"  indent="yes"/>
     
     <xsl:param name="currentPage"/>
     <xsl:variable name="source" select="1128" />
     <xsl:variable name="gen">&amp;<xsl:text disable-output-escaping="yes">test</xsl:text> </xsl:variable>
     
     <xsl:template match="/">
      <script type="text/javascript">
         <![CDATA[
      $(document).ready(
       function(){
        $('ul#advertisements').innerfade({
        speed: ]]>1<![CDATA[000,
        timeout: ]]><xsl:value-of select="$currentPage/data [@alias = 'interval']"/><![CDATA[000,
        type: 'random',
        containerheight: '20px'
       });
      });]]>
       </script>
       <div id="advertentie-inhoud"><a href="#" style="width:298px; height:247px; display:block; text-decoration:none;">&nbsp;</a></div>
       <div id="advertentie-kader">
        <ul id="advertisements" style="margin:0px; padding:0px;">
         <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node">
         <xsl:variable name="afbeelding" select="umbraco.library:GetMedia(data [@alias = 'AdvertentieImage'],'false')/data [@alias='umbracoFile']" />
          <li style="margin:0px; padding:0px;">
           <div  style="width:367px; height:247px; background-image:url(/umbraco/ImageGen.ashx?image={$afbeelding}{$gen})"><span class="advertentie-tekst-1"><span class="advertentie-tekst-2"><xsl:value-of select="data [@alias = 'AdvertentieText']"/></span></span></div>
          </li>
         </xsl:for-each>
        </ul>
       </div>
     </xsl:template>
    </xsl:stylesheet>

  • Douglas Robar 3570 posts 4671 karma points MVP ∞ admin c-trib
    Mar 23, 2010 @ 15:47
    Douglas Robar
    0

    The expanded "&amp;" on the querystring may look unusual but all browsers everywhere support it as if it were a simple "&" so it isn't a problem in actual usage.

    Beyond it looking odd, does it in fact work properly for you?

    cheers,
    doug.

  • Bas Schouten 135 posts 233 karma points
    Mar 23, 2010 @ 16:10
    Bas Schouten
    0

    Hi Doug,

    Thanx for your reply, i want to use it as a stylesheet backgroundimage, when i look in the outputsource the &amp; ends the stylesheet property, so the image wont work as it should.

    Cheers,

    Bas

  • Douglas Robar 3570 posts 4671 karma points MVP ∞ admin c-trib
    Mar 24, 2010 @ 14:17
    Douglas Robar
    0

    I have done something similar and it has worked just fine.

    In my case I need to select the appropriate banner image and display it as a div's background-image. The site editors select the banner from all those they've uploaded and I use ImageGen to enforce dimensions and such.

    I had thought of processing trying to process all the css with a macro to auto-generate the proper output. But then the css would change all the time and couldn't be cached on the browser.

    Then I thought I'd pre-populate the css with all the possible banner images as unique classes and just assign a class when the site editor selected a banner image. But that isn't maintainable since they may upload new banner images at any time and not remember to also update the css.

    What I ended up doing was using a macro to add a style="" statement in my markup to set the background-image. The end result of the markup looks like this:

    <div id="banner" style="background-image: url('/umbraco/imagegen.ashx?image=/media/1181/banner-Ski.png&amp;Class=banner');">

    In my template I have this:

    <div id="banner" style="<umbraco:Macro Alias='Style-BannerImage' runat='server'/>">

    And in my macro I have code for selecting the image from the document and then outputing the style information with:

    <xsl:text>background-image: url('/umbraco/imagegen.ashx?image=</xsl:text>
    <xsl:value-of select="$image" />
    <xsl:text>&amp;Class=banner');</xsl:text>

     

    There are other ways you might code this but this works well for me even with the &amp; in the markup and css.

    cheers,
    doug.

     

  • Josh Reid 182 posts 257 karma points
    Mar 25, 2010 @ 03:07
    Josh Reid
    0

    Definitely use single quotes around your background-image url.

    This will allow for the &amp; character as well as spaces in the file name, etc...

  • Bas Schouten 135 posts 233 karma points
    Mar 26, 2010 @ 09:40
    Bas Schouten
    0

    Hi Josh,

    Thats the solution! Thanx very much!

    Bas

  • 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