have you tried <xsl:value-of select="umbraco.library:GetMedia($imageRoot,
'true')/node/data[@alias='caption']"/> instead of <xsl:value-of select="$currentPage/data[@alias='caption']"/>
Javascript works perfectly in a normal web page with no xslt so i know its correct. i mean it gets random image and its corresponding caption on page refresh.
however when used inconjunction with the xslt it doesn't seem to refresh or regenerate a random number. The image and caption remain as per first page request.
I'm still investigating this but 98% there. thanks to you.
call template
Howdy pardners,
<xsl:call-template name="buildArray">
<xsl:with-param name="arrayNodes" select="umbraco.library:GetMedia($imageRoot, 'true')/node/data[@alias='umbracoFile']"/>
</xsl:call-template>
I'm using the xslt above. From what little i know of xslt the above is retrieving the umbracoFile value and passing to buildArray correct so far?
here's the build array part:
<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>
What I want to do is not only pass the umbracofile but also pass a caption (a property i added to the image datatype)
can some clever dude give me a clue as how to do this.
thanks everyone
>sajid
Not too sure what you're doing with the addtoArray stuff, but just to pass another parameter into your template is simple:
First add it to your call-template statement:
Then add it to the buildArray template
Hey Tom,
Thanks for the quick response buddy. great response too, but still not working.
yr xslt above nearly works. it brings back a random image but the caption does not change.
you see i uploaded images to my media section and gave them a caption too. So what i want is to bring back a random image and its associated caption.
here's the complete xslt if it helps:
<?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 = 'frontPageImages']"/>
<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:with-param name="imgCaption" select="umbraco.library:GetMedia($imageRoot, 'true')/node/data[@alias='caption']"/>
</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=400</xsl:text>
</xsl:attribute>
<xsl:attribute name="style">
<xsl:text>width:400px;</xsl:text>
</xsl:attribute>
</img>
<p id="caption">
<xsl:value-of select="$currentPage/data[@alias='caption']"/>
</p>
</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>
have you tried
<xsl:value-of select="umbraco.library:GetMedia($imageRoot, 'true')/node/data[@alias='caption']"/>
instead of
<xsl:value-of select="$currentPage/data[@alias='caption']"/>
Hi Sajid,
out of the top of my head I would do something like this:
Javascript
var myArray = new Array();
var randomValue;
//generate random number
function generateRandom(){
randomValue = Math.floor(Math.random() * myArray.length);
}
//get image url from array
function getUrl(){
return myArray[randomValue].url;
}
//get caption from array
function getCaption(){
return myArray[randomValue].caption;
}
function addtoArray(itemUrl, itemCaption){
var item = {url: itemUrl, caption: itemCaption};
myArray.push(item);
}
Xslt:
<xsl:call-template name="buildArray">
<xsl:with-param name="arrayNodes" select="umbraco.library:GetMedia($imageRoot, 'true')/node"/>
</xsl:call-template>
<xsl:value-of select="myFuncs:generateRandom()" />
<img>
<xsl:attribute name="src">
<xsl:text>/umbraco/imagegen.ashx?image=</xsl:text>
<xsl:value-of select="myFuncs:getUrl()"/>
<xsl:text>&width=400</xsl:text>
</xsl:attribute>
<xsl:attribute name="style">
<xsl:text>width:400px;</xsl:text>
</xsl:attribute>
</img>
<p id="caption">
<xsl:value-of select="myFuncs:getCaption()"/>
</p>
</xsl:template>
//pass in the whole media nodes which contain the url and caption, instead of just passing in the urls and caption texts separately
<xsl:template name="buildArray" >
<xsl:param name="arrayNodes"/>
<xsl:for-each select="$arrayNodes">
<xsl:value-of select="myFuncs:addtoArray(current()/data[@alias='umbracoFile'], current()/data[@alias='caption'])"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Hope that all makes sense,
Sascha
Many thanks dudes...you guys are terrific.
Sascha your code is Excellent man!!! thanx.
Javascript works perfectly in a normal web page with no xslt so i know its correct. i mean it gets random image and its corresponding caption on page refresh.
however when used inconjunction with the xslt it doesn't seem to refresh or regenerate a random number. The image and caption remain as per first page request.
I'm still investigating this but 98% there. thanks to you.
>sajid
Thanx Sascha...it worked.
changed: <xsl:value-of select="myFuncs:addtoArray(current()/data[@alias='umbracoFile'], current()/data[@alias='caption'])"/>
to: <xsl:value-of select="myFuncs:addtoArray(string(./data[@alias='umbracoFile']),string(./data[@alias='caption']))"/>
is working on a reply...