The expanded "&" 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?
Thanx for your reply, i want to use it as a stylesheet backgroundimage, when i look in the outputsource the & ends the stylesheet property, so the image wont work as it should.
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:
& 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&test)">test</div>
Is there a way to convert the & to a normal &
Thanx
Hi Bas
Would'nt it be solved if you write your variable like this:
<xsl:variable name="gen">&<xsl:text disable-output-escaping="yes"><![CDATA[test]]></xsl:text> </xsl:variable>
/Jan
Hi Jan,
It is not the solution. It still outputs the &
This is the full source:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
<!ENTITY amp "<![CDATA[&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">&<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;"> </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>
The expanded "&" 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.
Hi Doug,
Thanx for your reply, i want to use it as a stylesheet backgroundimage, when i look in the outputsource the & ends the stylesheet property, so the image wont work as it should.
Cheers,
Bas
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:
In my template I have this:
And in my macro I have code for selecting the image from the document and then outputing the style information with:
There are other ways you might code this but this works well for me even with the & in the markup and css.
cheers,
doug.
Definitely use single quotes around your background-image url.
This will allow for the & character as well as spaces in the file name, etc...
Hi Josh,
Thats the solution! Thanx very much!
Bas
is working on a reply...