Copied to clipboard

Flag this post as spam?

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


  • Nicolas 26 posts 46 karma points
    Oct 14, 2011 @ 20:56
    Nicolas
    0

    Filter a list of elements

    Hello,

    I have a list of elements, let's say it look like this :

              <items>
                <item>
                  <data alias="exemplesNode">1336</data>
                  <data alias="imageUrl">1105</data>
                </item>
                <item>
                  <data alias="exemplesNode">1336</data>
                  <data alias="imageUrl">1106</data>
                </item>
                <item>
                  <data alias="exemplesNode">1337</data>
                  <data alias="imageUrl">1106</data>
                </item>
              </items>

     

    I need to get a sublist of this list with only the item that have an exemplesNode set to 1336 . I need this so I can count how much element I have, and take a decision how to show it on my page (template will be different if there's is 0 of them).

    How can I make a select statement that will generate what I want?

    Thank you in advance!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Oct 14, 2011 @ 21:07
    Tom Fulton
    0

    This should do it:

     <xsl:variable name="goodItems" select="$yourNodeSet/items/item [data[@alias = 'exemplesNode'] = '1336']"/>

    Then you can do something like:

    <xsl:choose>
      <xsl:when test="$goodItems">there is > 0 items</xsl:when>
      <xsl:otherwise>0 items</xsl:otherwise>
    </xsl:choose>

    -Tom

  • Nicolas 26 posts 46 karma points
    Oct 14, 2011 @ 21:22
    Nicolas
    0

    Hello,

    Thanks! But I think that there is a problem. Here is the complete expression :

    "$currentPage/exempleImagesList/items/item [data[@alias = 'exemplesNode'] = '1336']" 

    But when using it, it's seems to search only in the first child "item". So it only returns the first node, but not the second.

    Do you know a fix for this?

    Thanks again!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Oct 14, 2011 @ 22:07
    Tom Fulton
    0

    Hmm..where are you putting the above code?  If you put it in a value-of it will only show the first, but in a variable it would work.  Maybe paste a bit more of your code

  • Nicolas 26 posts 46 karma points
    Oct 31, 2011 @ 17:09
    Nicolas
    0

    Hi,

    Sorry for my late respond.

    You are right! When I put the value of this variable in a for-each, it works! Thanks a lot!

Please Sign in or register to post replies

Write your reply to:

Draft