How do you do an XSLT foreach with MediaPicker getting list of images?
We have an XSLT foreach loop getting a list of images. It was working in 4.5 and 4.7 but in 4.9.1 it does not seem to be working.
I put a question on the Umbraco bug tracking but my issue was solved on there. I had an issue with getting an image I was using 'false' instead of 0.
So in my foreach I thought that the issue would be the same. I am not sure if the XSLT markup has changed from the way we did it before in 4.7. So any suggestion would be great. It does not seem to be getting the image paths correctly. Am I doing this correctly? Thanks in advance
I took the liberty to move this post into the XSLT category ;-)
I'm not sure why it's neccesary to use the umbraco.library:GetXmlNodeCurrent() extension? Would'nt it be enough to use $currentPage?
Also...I'm a bit puzzled if this has ever been working since you're using @nodeTypeAlias, which is the old XML schema used before v4.5 - I don't suppose you're using the legacy schema?
Must admit that I can't remember what XML is returned when doing something like: <xsl:variable name="images" select="umbraco.library:GetMedia($currentPage/slideshowMediaFolder,1)" /> but please try and make this variable and write it out in
And tell me what it returns...If I remember correctly it would be something like <folder><image /><image /></folder>...if so the your for-each can be like
Yeh, I know, I have switched over to Razor mode so my XSLT is very rusty. So I tried the textarea and it didn't spit out anything. Actually it spit out the whole HTML inside the text area. That was kind of funny.
I think I did have the old schema in there. The reason I used the umbraco.library:GetXmlNodeCurrent() is because I am calling multiple XSLT files into 1 XSLT file and the $currentPage was conflicting with eachother if you have more than on XSLT file being called into one file. I have about 15 being called into 1 file.
I will keep plugging away at this. It really seems like it should be something very simple. For some reason I have to use false() instead of true() or 0 instead of 1. One way I have it getting my foreach it is getting the correct amount of images by spitting out the image tags but the 'src' is blank.
So if I do this it spits out the correct amount of <img> tags but no src. I guess I am having the most issue with just getting the file name back. That is my problem.
Yeh, I have no idea. I have tried adding the /Image like I have seen in just about ALL other examples, but then I can't even get the tags to show up again. I am just going to switch over everything to Razor. This has gotten too frustrating for me. The old schema for some odd reason or another randomly will show the images in the slideshow. Then when you go back to the page the image tags get pulled again. I have no idea what the deal is.
This seems to be only an issue on our end. I just tried this and it still didn't spit out anything. Seems like too much work for something that I have tested and seems to work fine in Razor.
What happens if you set the second parameter to 1 instead of false()? 1 should give you all the xml children as well where 0/false() would just give you the xml for the chosen node.
The initial codesnippet you supplied should actually work (as you expected) - I see no reason for it not to, other than the snippet not being called on the page you expect it to...
Regarding @nodeTypeAlias: Media is an exception with this one - all media nodes actually still have this attribute in the new schema, even though it's a duplicate of the node's name (but the XPath is simpler just using the name: e.g.: GetMedia(XXX, true())//Image )
The second example you post, you've changed to false() for the second parameter, which will only give you the Folder and its properties, but because you're using descendant-or-self::* with no predicate, your for-each iterates the Folder element and its <contents/> child (actually the "Folder browser" property) so you're getting at least two <img src="" /> in the output (+ any additional properties you may have added to the Folder media type)
The last example you posted should also work, once you change from false() to true() - you need that to also get the Folder's contents.
So, provided GetXmlNodeCurrent() actually works, you seem to have assumed the right things, so we should be able to crack this ...
How do you do an XSLT foreach with MediaPicker getting list of images?
We have an XSLT foreach loop getting a list of images. It was working in 4.5 and 4.7 but in 4.9.1 it does not seem to be working.
I put a question on the Umbraco bug tracking but my issue was solved on there. I had an issue with getting an image I was using 'false' instead of 0.
So in my foreach I thought that the issue would be the same. I am not sure if the XSLT markup has changed from the way we did it before in 4.7. So any suggestion would be great. It does not seem to be getting the image paths correctly. Am I doing this correctly? Thanks in advance
Hi Carlos
I took the liberty to move this post into the XSLT category ;-)
I'm not sure why it's neccesary to use the umbraco.library:GetXmlNodeCurrent() extension? Would'nt it be enough to use $currentPage?
Also...I'm a bit puzzled if this has ever been working since you're using @nodeTypeAlias, which is the old XML schema used before v4.5 - I don't suppose you're using the legacy schema?
Must admit that I can't remember what XML is returned when doing something like: <xsl:variable name="images" select="umbraco.library:GetMedia($currentPage/slideshowMediaFolder,1)" /> but please try and make this variable and write it out in
<textarea>
<xsl:copy-of select="$images" />
</textarea>
And tell me what it returns...If I remember correctly it would be something like <folder><image /><image /></folder>...if so the your for-each can be like
<xsl:for-each select="$images/folder/image">
<img src="{.}" />
</xsl:for-each>
(We'll let Chriztian come up with the super solution later ;-)).
Looking forward to hearing from you.
/Jan
Yeh, I know, I have switched over to Razor mode so my XSLT is very rusty. So I tried the textarea and it didn't spit out anything. Actually it spit out the whole HTML inside the text area. That was kind of funny.
I think I did have the old schema in there. The reason I used the umbraco.library:GetXmlNodeCurrent() is because I am calling multiple XSLT files into 1 XSLT file and the $currentPage was conflicting with eachother if you have more than on XSLT file being called into one file. I have about 15 being called into 1 file.
I will keep plugging away at this. It really seems like it should be something very simple. For some reason I have to use false() instead of true() or 0 instead of 1. One way I have it getting my foreach it is getting the correct amount of images by spitting out the image tags but the 'src' is blank.
So if I do this it spits out the correct amount of <img> tags but no src. I guess I am having the most issue with just getting the file name back. That is my problem.
Yeh, I have no idea. I have tried adding the /Image like I have seen in just about ALL other examples, but then I can't even get the tags to show up again. I am just going to switch over everything to Razor. This has gotten too frustrating for me. The old schema for some odd reason or another randomly will show the images in the slideshow. Then when you go back to the page the image tags get pulled again. I have no idea what the deal is.
This seems to be only an issue on our end.
I just tried this and it still didn't spit out anything. Seems like too much work for something that I have tested and seems to work fine in Razor.
If anyone else has the same issue as we are having I may comeback and revisit this but for now I am moving forward with our Razor solution.
Hi Carlos
What happens if you set the second parameter to 1 instead of false()? 1 should give you all the xml children as well where 0/false() would just give you the xml for the chosen node.
/Jan
Hi Carlos & Jan,
Reading through this, I have some comments:
is working on a reply...