I'm using the xslt below to get random images from a sub folder named bannerImages on my dev machine. But at times it seems to bring up the open with dialogue (i.e. browser does not know the extension and what to open it with). Sometimes it just shows the HTML in the browser window.
The idea of the xslt is to bring back a random image for the banner. I created a subfolder in the media folder named BannerImages. On my master page I added a mediapicker property name bannerImages which was linked to the BannerImages folder. Please advise me if the xslt is right or a better way of doing what i'm trying to do:
Tommy, yes the urls are comming back fine. Also the page seems to render fine at times.
and then sometimes when I click on a page link the browser takes sometime to think about it and shows the dialogue asking me what application I wish to open the aspx page with i.e. notepad, word pad etc etc. and sometimes I get the html viewable in the browser with a message at the top of the browser saying "object not found"
I thought it could've been the javascript but It seems ok.
If anyone has the time to test it I did it like this.
I created a subfolder in media section, under media folder, named Banner Images.
on my master page i added a mediapicker property named BannerImages, with an alias of bannerImages.
I then set the BannerImages property to point at the BannerImages folder in the media section.
The xslt was created as above and the corresponding macro inserted on the master page.
Just when I have the randomBanner xslt. The strange thing is that it works ok most of the time. But when I start clicking between links the open dialogue just pops up intermittantly. I originally thought the problem was with the javascript but that seems fine.
Random Banner Images
Hi Guys,
I'm using the xslt below to get random images from a sub folder named bannerImages on my dev machine. But at times it seems to bring up the open with dialogue (i.e. browser does not know the extension and what to open it with). Sometimes it just shows the HTML in the browser window.
The idea of the xslt is to bring back a random image for the banner. I created a subfolder in the media folder named BannerImages. On my master page I added a mediapicker property name bannerImages which was linked to the BannerImages folder. Please advise me if the xslt is right or a better way of doing what i'm trying to do:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:myFuncs="urn:my-scripts"
exclude-result-prefixes="msxml myFuncs umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="imageRoot" select="$currentPage/ancestor-or-self:: node[@level = 1]/data [@alias = 'bannerImages']"/>
<msxsl:script implements-prefix="myFuncs" language="JavaScript">
<![CDATA[
var myArray = new Array();
function random(){
var index = Math.floor(Math.random() * myArray.length);
return myArray [index];
}
function addtoArray(item){
myArray.push(item);
}
]]>
</msxsl:script>
<xsl:template match="/">
<xsl:call-template name="buildArray">
<xsl:with-param name="arrayNodes" select="umbraco.library:GetMedia($imageRoot, 'true')/node/data[@alias='umbracoFile']"/>
</xsl:call-template>
<img>
<xsl:attribute name="src">
<xsl:text>/umbraco/imagegen.ashx?image=</xsl:text>
<xsl:value-of select="myFuncs:random()"/>
<xsl:text>&width=200</xsl:text>
</xsl:attribute>
</img>
<br />
<xsl:value-of select="myFuncs:random()"/>
</xsl:template>
<xsl:template name="buildArray" >
<xsl:param name="arrayNodes"/>
<xsl:for-each select="$arrayNodes">
<xsl:value-of select="myFuncs:addtoArray(string(./text()))"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Hi Sajid, if you skip rendering the images but just displays the random urls, do they look correct ?
>Tommy
Sounds like a browser/OS problem instead of XSLT problem...
Ps. you can change this:
<img>
<xsl:attribute name="src">
<xsl:text>/umbraco/imagegen.ashx?image=</xsl:text>
<xsl:value-of select="myFuncs:random()"/>
<xsl:text>&width=200</xsl:text>
</xsl:attribute>
</img>
Into this as far as I know:
<img src="/umbraco/imagegen.ashx?image={myFuncs:random()}&width=200" />
Kipusoep thanks for the shorthand way!
Tommy, yes the urls are comming back fine. Also the page seems to render fine at times.
and then sometimes when I click on a page link the browser takes sometime to think about it and shows the dialogue asking me what application I wish to open the aspx page with i.e. notepad, word pad etc etc. and sometimes I get the html viewable in the browser with a message at the top of the browser saying "object not found"
I thought it could've been the javascript but It seems ok.
If anyone has the time to test it I did it like this.
I created a subfolder in media section, under media folder, named Banner Images.
on my master page i added a mediapicker property named BannerImages, with an alias of bannerImages.
I then set the BannerImages property to point at the BannerImages folder in the media section.
The xslt was created as above and the corresponding macro inserted on the master page.
thanks any help was be much approciated!
Sajid
Is this only a problem with this page, or is it a general problem with your site?
>Tommy
Hi Tommy,
Just when I have the randomBanner xslt. The strange thing is that it works ok most of the time. But when I start clicking between links the open dialogue just pops up intermittantly. I originally thought the problem was with the javascript but that seems fine.
thanks
Sajid
Tommy, the urls look something like: /media/19/xyz.jpg, where 19 I think is the id of the subfolder.
Weird. And when you see the problem, is it then reproducable (i.e. clicking the link several tims will result in the same behavior) ?
I would suspect the scavascript also - have you tried stepping through using Firebug?
... or make the random() function return a hardcoded image everytime.
And maybe try to dump the content of your array.
Ok Not used Firebug for that.
Once the pop up appears it then appears almost again, but takes several clicks to open up.
Tommy your last post about returning the hardcoded image and the then dump the content of the array.
Can you explain how I will do this?
thanks again for your time
Sajid
Hi Sajid, I'll be happy to help you out - but I need to put it on hold for couple of hours. I will revert tonight.
For returning a hardcoded image you have to modify random() function to something like this
function random(){
return 'myhardcodedimageurl.jpg';
}
>Tommy
Hi Sajid, you source code is working perfectly it my site - no problems, so I wonder if all the entries in your "bannerImages" are valid images?
>Tommy
Tommy, I placed the banner on my master page.
and what I was doing was moving betwenn pages rapidly, just testing the speed of page load.
did you try this on yr site?
I tried changing pages quickly - no problem.
Ok Tommy thanks for that. Much Appreciated.
Tommy, is your site live or on local host?
I had 4 banner images all of type jpg.
it's on localhost, and I also had 4 banners of type jpg.
ok Tommy thanks for checking this out for me.
Sajid
Incase any body gets similar problem. The problem was with the jpg.
I'm not sure if the size of the image was the problem. But when i deleted an image everything was ok.
is working on a reply...