Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Carlos 338 posts 472 karma points
    Dec 28, 2012 @ 21:46
    Carlos
    0

    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

    <xsl:for-each select="umbraco.library:GetMedia(umbraco.library:GetXmlNodeCurrent()/slideshowMediaFolder,1)/descendant-or-self::*[@nodeTypeAlias='Image']">
     <img src="{umbracoFile}" title="{caption}" alt="{altTag}" data-caption="#Image_{@id}"/>
    </xsl:for-each>

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 28, 2012 @ 22:33
    Jan Skovgaard
    0

    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

  • Carlos 338 posts 472 karma points
    Dec 28, 2012 @ 22:59
    Carlos
    0

    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.

     

    <xsl:variable name="imgFolderPath" select="umbraco.library:GetMedia(umbraco.library:GetXmlNodeCurrent()/slideshowMediaFolder, false())/descendant-or-self::*" />
    <xsl:for-each select="$imgFolderPath">
    <img src="{umbracoFile}" />
    </xsl:for-each>

     

  • Carlos 338 posts 472 karma points
    Dec 28, 2012 @ 23:31
    Carlos
    0

    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.

    <xsl:variable name="images" select="umbraco.library:GetXmlNodeCurrent()/slideshowMediaFolder"/>
          <xsl:variable name="mediaItems" select="umbraco.library:GetMedia($images, false())"/>
        <xsl:for-each select="$mediaItems/Image">
            <xsl:variable name="imgFile" select="umbracoFile"/>
        <img>
               <xsl:attribute name="src">
                  <xsl:value-of select="$imgFile"/>
                 </xsl:attribute>
            </img>
        </xsl:for-each>

    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.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 29, 2012 @ 12:14
    Jan Skovgaard
    0

    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

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 30, 2012 @ 00:08
    Chriztian Steinmeier
    0

    Hi Carlos & Jan,

    Reading through this, I have some comments:

    1. 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...
    2. 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 )
    3. 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)
    4. 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 ...
    /Chriztian
Please Sign in or register to post replies

Write your reply to:

Draft