Copied to clipboard

Flag this post as spam?

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


  • AntonioMX 58 posts 57 karma points
    Dec 17, 2009 @ 19:57
    AntonioMX
    0

    Get Dropdown Multiple Selected Items and Compare

    Hello, I am trying to get to work a tagging system for the images in the media section. I added a multiple dropdown list as part of the Image datatype, and I have previously filled the multiple dropdown list with prevalues.

    I have been trying to loop all the images in a particular sub-folder in the media section and to check if the selected prevalues are matching the ones set in the doc type.

    Here is the code I have borrowed from here and some good ideas from here and here

    So far I just want to loop through all the images in the selected subfolder and list the matching prevalues. But I get a error on this one:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
        <!ENTITY nbsp "&#x00A0;">
    ]>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="msxml umbraco.library">     <xsl:output method="xml" omit-xml-declaration="yes"/>     <xsl:param name="currentPage"/>     <!-- MAIN TEMPLATE -->
        <xsl:template match="/">
        <!-- Variable with the selected media folder ID -->
            <xsl:variable name="mediaFolderID" select="$currentPage/data[@alias='SelectedFolder']"/>         <!-- Call template generates the HTML for the images-->
            <xsl:call-template name="LoopThroughImagesInFolder">
                <xsl:with-param name="mediaFolderID">
                        <xsl:value-of select="$mediaFolderID"/>
                </xsl:with-param>
            </xsl:call-template>     </xsl:template>     <!-- LOOP THROUGH IMAGES IN FOLDER TEMPLATE -->
        <xsl:template name="LoopThroughImagesInFolder">
            <!-- Parameter with a media folder ID -->
            <xsl:param name="mediaFolderID"/>         <!-- Check that you really have an ID -->
            <!-- Without this test the script can fail -->
            <xsl:if test="$mediaFolderID &gt; 0">
               
                <!-- Get the media node using the ID -->
                <xsl:variable name="images" select="umbraco.library:GetMedia($mediaFolderID, 1)" />             <!-- Check if the folder contains any child nodes -->
                <xsl:if test="count($images/node) &gt; 0">;       <!-- Start iterating the child nodes -->
                    <xsl:for-each select="$images/node">                     <xsl:choose>
                            <!-- Is it an image?
                            Please note that this only works if your images have the
                            @nodeTypeAlias "Image". If you have called it something else,
                            you need to replace the name.
                            -->
                            <xsl:when test="string(./@nodeTypeAlias) = 'Image'">
                                <!-- Print the image code -->
        <ul>
         <xsl:for-each select="umbraco.library:GetPreValues($currentPage)//preValues">
         <li>
                 <a href="#">
           <xsl:value-of select="." />
          </a>               
         </li>
         </xsl:for-each>
        </ul>
                            </xsl:when>
                        </xsl:choose>
                    </xsl:for-each>
                </xsl:if>
            </xsl:if>  </xsl:template>
    </xsl:stylesheet>
  • AntonioMX 58 posts 57 karma points
    Dec 17, 2009 @ 21:01
    AntonioMX
    0

    Sorry, so far I just want to list all the values selected, not to compare them to anything, but I can't seem to get it to work.

  • AntonioMX 58 posts 57 karma points
    Dec 18, 2009 @ 00:42
    AntonioMX
    0

    Alright, trying a different approach. Based on this one.

    I created a new datatype named tags which renders a checkbox list control with some prevalues inserted.

    then modified the "Image" media type and added the tags datatype.

    Then on some random template I inserted a macro that calls the following xslt:

     <xsl:variable name="filterBy" select="umbraco.library:RequestQueryString('CityStreets')" />
     <xsl:for-each select="umbraco.library:GetXmlNodeById('1537')/nodes">
      <xsl:if test="contains(./data[@alias='tags'], $filterBy)">
           <p>Do Something</p>
      </xsl:if>
     </xsl:for-each>

    But this doesn’t work, the <p>Do Something</p> paragraph never shows up, the 1537 node refers to a media folder under which are all the images.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Dec 18, 2009 @ 01:15
    Chriztian Steinmeier
    0

    Hi Antonio,

    You cannot retrieve XML for nodes in the Media section with the GetXmlNodeById() function - You should use the GetMedia() function for that, and send 'true' as the second argument to signal that you want the contents of a folder:

    <xsl:variable name="filterBy" select="umbraco.library:RequestQueryString('CityStreets')" />
    <xsl:variable name="mediaNodes" select="umbraco.library:GetMedia('1537')" /> <xsl:for-each select="$mediaNodes/node"> <xsl:if test="contains(data[@alias = 'tags'], $filterBy)"> <p>Do Something</p> </xsl:if> </xsl:for-each>

    - Lets hear how that works,

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Dec 18, 2009 @ 01:17
    Chriztian Steinmeier
    0

    .. aaand then I just forgot to include the 'true' part I wrote about :-)

    <xsl:variable name="filterBy" select="umbraco.library:RequestQueryString('CityStreets')" />
    <xsl:variable name="mediaNodes" select="umbraco.library:GetMedia('1537', 'true')" />
    <xsl:for-each select="$mediaNodes/node">
            <xsl:if test="contains(data[@alias = 'tags'], $filterBy)">
                    <p>Do Something</p>
            </xsl:if>
    </xsl:for-each>

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft