Copied to clipboard

Flag this post as spam?

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


  • Eric 12 posts 32 karma points
    Feb 05, 2013 @ 22:02
    Eric
    0

    Filtering Foreach by class

    I am trying to filter a foreach in an xslt by a class. 

    In content I have the following nodes: swatches, blankets, signs, decals. I am using a drop down to display the node, then using jQuery I am setting a class="selected" on the chosen node. I wish to display it's child nodes in a separate text area. 

    I can display all of the child nodes for each of the parent nodes using this for-each:

    <xsl:for-each select="$currentPage/OrderGroup/OrderItem">

    However I can not filter by the "selected" class. 

    Is there a way I can capture the Id of the node in jQuery and filter by that Id in the other text area?

     

     

     

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Feb 05, 2013 @ 22:10
    Jan Skovgaard
    0

    Hi Eric

    Could you show us the code you have so far?

    /Jan

  • Eric 12 posts 32 karma points
    Feb 05, 2013 @ 22:16
    Eric
    0

    <label for="file" class="label"><h4><b>Category</b></h4>
          <span class="selectMultiple multiple anthracite-gradient replacement" style="width:200px" tabindex="0"><span class="drop-down">
            <xsl:for-each select="$currentPage/OrderGroup">            
              <xsl:choose>
              <xsl:when test="position() = 1">
                <span class="listing selected"><xsl:value-of select="@nodeName"/></span>
              </xsl:when>
              <xsl:otherwise>
                <span class="listing"><xsl:value-of select="@nodeName"/></span>
              </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
            </span>
          </span>
        </label>

        <div class="field-block button-height" style="margin-top:auto;">
          <h4><b>Item</b></h4>
          <span class="selectMultiple multiple anthracite-gradient replacement" style="width:650px" tabindex="0">
            <span class="drop-down">
              <xsl:for-each select="$currentPage/OrderGroup/OrderItem">
                <span class=""><xsl:value-of select="@nodeName"/></span>
              </xsl:for-each>  
            </span>
          </span>
        </div>
      </div>

    The top section is displaying the parent nodes: Swatches, Blankets, Hangtags, Posters, etc. Then I'm setting the class on the <span> to "selected" onclick.

    The bottom is displaying the child nodes for every parent. This is where I want to limit to only show the nodes where the class is selected.

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Feb 05, 2013 @ 22:17
    Chriztian Steinmeier
    0

    Hi Eric,

    Just to clarify: XSLT happens on the server — jQuery happens in the browser.

    To have those "talk" to each other, they'll need to leave a trail behind for the other to pickup...

    From XSLT you can set a data-attribute on the element in question, which jQuery can read.

    From the browser you'll need to either set a cookie, or put a parameter in the page's QueryString (both require a new request)

    How is the "selected" class available on the OrderItem elements? Is it a separate childnode, or an attribute?

    /Chriztian

  • Eric 12 posts 32 karma points
    Feb 05, 2013 @ 22:28
    Eric
    0

    Chriztian,

    Thank you for your response! Thanks for clarifying that for me also. I didn't know if it was possible to have those"talk" to each other. I will be looking into what you suggested. I have never done anything like this before. The "selected" class is an attribute not a childnode. 

    Eric

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies