I have the code below which im using to iterate through 2 Multi-Node tree pickers and then insert both of the retrieved images into list items. I'm having trouble making so that it actually "merges" the items selected from both pickers instead of listing one then the other. Any help would be greatly appreciated!
So something like this Jan? I'm getting an int32 error, and an error on the front-end if I skip testing...Am I misunderstanding?
<xsl:template name="backgroundImage"> <xsl:if test="$currentPage/headerBackgroundImage/MultiNodePicker/nodeId"> <!-- Loop through each of the nodeId values -->
Thanks Jan! So when I call the templates, how do I make it loop for each item in the Multi-node picker? Something like below just returns the same items over and over instead of proceeding to the next one...
Ah, forgive me for being a bit slow on this. NOW I get what it is that you want to achieve. I thought you only wanted the first image from both variables.
You need to mix the two results you're getting from the variables above.
So try doing this instead. (from the top of my head - be aware of potential typos)
Hmm, that just returns an empty <ul/>... Not throwing any errors and I added xmlns:msxsl="urn:schemas-microsoft-com:xslt" and exclude-result-prefixes="msxsl.." to the stylesheet portion. Any ideas?
Hmm, what happens if you just write out the $background variable like this <xsl:value-of select="$background" /> - does that give you an id? If so, what xml does it return if you make a
What i'm thinking is that perhaps the reason why we got nothing returned earlier on was that the variable was defined outside the xsl:template match="/" - I'm not sure however. But since you can get the xml by making a copy-of on the $backgroundImage variable it should be possible to fetch the nodeId's in the loop.
Select just one item in template
Hi,
I have the code below which im using to iterate through 2 Multi-Node tree pickers and then insert both of the retrieved images into list items. I'm having trouble making so that it actually "merges" the items selected from both pickers instead of listing one then the other. Any help would be greatly appreciated!
Thanks,
Amir
Hi Amir
How do you want to have the images displayed? Could you ellaborate a bit more on exactly what you're trying to achieve? :)
Not sure I understand your issue completely.
/Jan
Hi Jan,
So what I'd like to achieve is:
What I'm getting is:
Thanks!
Amir
Hi Amir
Ah yes, now I get it :)
But can't you just skip the loop and then just do the following
<xsl:variable name="backgroundImage" select="$currentPage/headerBackgroundImage/MultiNodePicker/nodeId" />
<xsl:variable name="factImage" select="$currentPage/headerFactPicker/MultiNodePicker/nodeId" />
This should simply just return the first node for each of your selections.
Hope this helps.
/Jan
So something like this Jan? I'm getting an int32 error, and an error on the front-end if I skip testing...Am I misunderstanding?
Hi Amir
Not exactly - sorry that I was not more thorough in my previous answer.
It's more like this
<xsl:variable name="backgroundImage" select="$currentPage/headerBackgroundImage/MultiNodePicker/nodeId" />
<xsl:variable name="node" select="umbraco.library:GetMedia($backgroundImage,0)" />
<img src="{$node/umbracoFile}" alt="[image]" height="{$node/umbracoHeight}" width="{$node/umbracoWidth}" />
This should work.
/Jan
Thanks Jan! So when I call the templates, how do I make it loop for each item in the Multi-node picker? Something like below just returns the same items over and over instead of proceeding to the next one...
<xsl:for-each select="$currentPage/headerBackgroundImage/MultiNodePicker/nodeId">
Hi Amir
Ah, forgive me for being a bit slow on this. NOW I get what it is that you want to achieve. I thought you only wanted the first image from both variables.
You need to mix the two results you're getting from the variables above.
So try doing this instead. (from the top of my head - be aware of potential typos)
<xsl:variable name="backgroundImage" select="$currentPage/headerBackgroundImage/MultiNodePicker/nodeId" />
<xsl:variable name="factImage" select="$currentPage/headerFactPicker/MultiNodePicker/nodeId" />
<xsl:variable name="images">
<root>
<xsl:for-each select="backgroundImage">
<image>
<id type="background">
<xsl:value-of select="." />
</id>
</image>
</xsl:for-each>
<xsl:for-each select="factImage">
<image>
<id type="fact">
<xsl:value-of select="." />
</id>
</image>
</xsl:for-each>
</root>
</xsl:variable>
<xsl:template match="/">
<ul>
<xsl:apply-templates select="msxsl:node-set($images)/image" />
</ul>
</xsl:template>
<xsl:template match="image">
<li>
<xsl:apply-templates select="image/id[@type='background']" />
<xsl:apply-templates select="image/id[@type='fact']" />
</li>
</xsl:template>
<xsl:template match="id[@type='background']">
<xsl:variable name="image" select="umbraco.library:GetMedia(.,0)" />
<img src="{$image}" alt="" />
</xsl:template>
<xsl:template match="id[@type='fact']">
<xsl:variable name="image" select="umbraco.library:GetMedia(.,0)" />
<span><img src="{$image}" alt="" /></span>
</xsl:template>
Remember to declare msxsl as a namespace in the xsl:stylesheet section.
Hope this helps.
/Jan
Hmm, that just returns an empty <ul/>... Not throwing any errors and I added xmlns:msxsl="urn:schemas-microsoft-com:xslt" and exclude-result-prefixes="msxsl.." to the stylesheet portion. Any ideas?
Thanks again,
Amir
Hi Amir
Hmm, ok. Try doing this
<textarea>
<xsl:copy-of select="msxsl:node-set($images)" />
</textarea>
Does that return any XML?
/Jan
Hi Jan, that just returns the following.
Hi Amir
Oops, seems like I forgot to run the loop on the variables...
in the for-each it just says "backgroundImage" and "factImage". it should be $backgroungImage and $factImage like
<xsl:for-each select="$backgroundImage"> and <xsl:for-each select="$factImage">
/Jan
Hi Jan, Sorry for the VERY late response, this is still returning an empty list..
Thanks again,
Amir
Hi Amir
What does your full code look like now?
/Jan
Here it is Jan, again, thanks a TON for all of your help.
Hi Amir
You're welcome :)
Hmm, what happens if you just write out the $background variable like this <xsl:value-of select="$background" /> - does that give you an id? If so, what xml does it return if you make a
<textarea>
<xsl:copy-of select="$background" />
</textarea>
/Jan
Did you mean $backgroundImage? so like the following? It still returns nothing...
Hi Amir
Try placing it in the template that matchens "/" like this:
<xsl:template match="/">
<xsl:value-of select="$backgroundImage" /> <br />
<textarea>
<xsl:copy-of select="$backgroundImage" />
</textarea>
<!-- rest of your code in this template -->
</xsl:template>
Yay! i get something, is this what was intended?
Hi Amir
ok, that is good.
Try moving the $images variable into the <xsl:template match="/"> template. Like this
<xsl:template match="/">
<xsl:variable name="images">
<!-- the for-each loops goes here -->
</xsl:variable>
</xsl:template>
And please let me see the whole code structure afterwards :)
/Jan
Ah, back to just an empty <ul/>
That makes sense, since you changed the $images variable, which was not the intention :)
The whole code should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:msxsl="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" xmlns:ucomponents.media="urn:ucomponents.media"
exclude-result-prefixes="msxml
umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes
Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings
Exslt.ExsltSets ucomponents.media ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="backgroundImage" select="$currentPage/headerBackgroundImage/MultiNodePicker/nodeId" />
<xsl:variable name="factImage" select="$currentPage/headerFactPicker/MultiNodePicker/nodeId" />
<xsl:template match="/">
<xsl:variable name="images">
<root>
<xsl:for-each select="backgroundImage">
<image>
<id type="background">
<xsl:value-of select="." />
</id>
</image>
</xsl:for-each>
<xsl:for-each select="factImage">
<image>
<id type="fact">
<xsl:value-of select="." />
</id>
</image>
</xsl:for-each>
</root>
</xsl:variable>
<ul>
<xsl:apply-templates select="msxsl:node-set($images)/image" />
</ul>
</xsl:template>
<xsl:template match="image">
<li>
<xsl:apply-templates select="image/id[@type='background']" />
<xsl:apply-templates select="image/id[@type='fact']" />
</li>
</xsl:template>
<xsl:template match="id[@type='background']">
<xsl:variable name="image" select="umbraco.library:GetMedia(.,0)" />
<img src="{$image}" alt="" />
</xsl:template>
<xsl:template match="id[@type='fact']">
<xsl:variable name="image" select="umbraco.library:GetMedia(.,0)" />
<span><img src="{$image}" alt="" /></span>
</xsl:template>
</xsl:stylesheet>
What i'm thinking is that perhaps the reason why we got nothing returned earlier on was that the variable was defined outside the xsl:template match="/" - I'm not sure however. But since you can get the xml by making a copy-of on the $backgroundImage variable it should be possible to fetch the nodeId's in the loop.
Let's see if it works :)
/Jan
Back to the empty UL again...Thanks again for helping with this, I think I'm starting to actually see what's going on.
argh, sorry! Once again I forgot to place the $ sign in front of the bakcgroungImage and factImage variables in the for-each loops.
It should of course be $backgroundImage and $factImage.
Hope this does the trick now...:)
/Jan
Its actually still returning nothing, Is this one of those tasks that would be super simple in Razor?
is working on a reply...