Copied to clipboard

Flag this post as spam?

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


  • Phil Crowe 192 posts 256 karma points
    Oct 22, 2010 @ 11:46
    Phil Crowe
    0

    Find Nodes Based on values in string

    I have a custom datatype property that returns a string on node names separated by commas like so "blue,black,red" in xslt is there anyway i can use this to identify nodes by their names, then list them on the front end? i know i could do this with c# using the nodefactory but was hoping there is a way i could do it in xslt?

  • Rich Green 2246 posts 4008 karma points
    Oct 22, 2010 @ 12:02
    Rich Green
    0

    Hi Phil,

    Couldn't you save the node id's in your custom property instead, then you could use split them and use umbraco.library:GetXmlNodeById ?

    Rich

  • Phil Crowe 192 posts 256 karma points
    Oct 22, 2010 @ 12:31
    Phil Crowe
    0

    Hi Rich, Can you give me an example of how i can 'split' them?

  • Rich Green 2246 posts 4008 karma points
    Oct 22, 2010 @ 12:45
    Rich Green
    0

    Sure

    <xsl:variable name="colours" select="1092,1011,1012" />
    
    <xsl:variable name="splitcolours" select="umbraco.library:Split($colours, ',')" />
    <xsl:for-each select="$splitcolours/value">
    
    <xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById(.)"/>
    
    <li>
    <a href="{umbraco.library:NiceUrl($currentNode/@id)}"><xsl:value-of select="$currentNode/@nodeName"/></a>
    </li>
    
    </xsl:for-each>
    
    Make sense?
    Rich
  • Phil Crowe 192 posts 256 karma points
    Oct 22, 2010 @ 14:15
    Phil Crowe
    0

    to be honest ive never managed to get to grips totally with xslt. Below is my code. The divs with the class 'weloveitem' i what i am wanting to create a new loop around.

    each item that is being looped through has a property 'associatedProducts' which is the one that returns a string value ('blue,black,red'). So i need to create a loop within the below loop that then displays the nodes specified in the string. I have amended my customer datatype so that it saves the node id's but i cant get this xslt to work. when i try adding the variables you suggested i just keep getting an 'error at line' error.

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
      
    <xsl:for-each select="$currentPage/* [@isDoc and string(@id) != '2144']">
      <div class="ProductCategoryContainer">
        <img src="{concat(substring-before(mainShot,'.'), '.jpg')}" alt="{@nodeName}" width="160" height="120" class="productCategoryImage" />
        <h2>
          <href="{umbraco.library:NiceUrl(@id)}?categoryId=1">
            <xsl:value-of select="@nodeName" />
          </a>
        </h2>
        <xsl:for-each select="./* [@isDoc]">
          <ul class="subCategoryListOnCategoryPage">
            <li><href="{umbraco.library:NiceUrl(@id)}?searchingForProduct=1"><xsl:value-of select="@nodeName"/></a></li>
          </ul>
        </xsl:for-each>
        <div class="weLoveBox">

          <p><b>We love:</b></p>
          <div class="weLoveHolder">
            
            <div class="weLoveItem">1</div>
            <div class="weLoveItem">2</div>
            <div class="weLoveItem">3</div>
            
          </div>
        </div>
      </div>
      
      </xsl:for-each>


    </xsl:template>

    </xsl:stylesheet>

  • Rich Green 2246 posts 4008 karma points
    Oct 22, 2010 @ 15:21
    Rich Green
    0

    Which property holds the split ID's from your custom control in the above XSLT?

    Rich 

  • Phil Crowe 192 posts 256 karma points
    Oct 22, 2010 @ 15:52
    Phil Crowe
    0

    Product Page 
    -----subcategory
      ---product
    ---product

    The products page contains the property that has the comma separated string created by the custom control, this property is called "associatedProducts". the xslt is on the products page. currently it displays all the sub categories, then the products beneath them in this bit:

        
    <xsl:for-each select="./* [@isDoc]">
          <ul class="subCategoryListOnCategoryPage">
            <li><href="{umbraco.library:NiceUrl(@id)}?searchingForProduct=1"><xsl:value-of select="@nodeName"/></a></li>
          </ul>
        </xsl:for-each>


    I want to then create another loop in the 'weloveholder' div like this (i know this is incorrect syntax):
          <div class="weLoveHolder">
            <xsl:for-each select="./* [@id = $seperatedValueId]">
             <div class="weLoveItem"><xsl:value-of select="@nodeName" /></div>
            </xsl:for-each>
          </div>

    basically after somehow separating the id's i then need to check if any the node ids of the product pages match any of the ones in the
    string returned by my 'associatedproducts' property. Just a thought. Could i do a 'contains' match with the nodeid and the associated
    products string?

  • Rich Green 2246 posts 4008 karma points
    Oct 22, 2010 @ 15:59
    Rich Green
    0

    This code should work as long as your getting a value into @currentPage/associatedProducts

    <xsl:variable name="products" select="$currentPage/associatedProducts"/>

    <xsl:variable name="splitproducts" select="umbraco.library:Split($products, ',')" />
    <xsl:for-each select="$splitproducts/value">

    <xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById(.)"/>
        
    <xsl:if test="$currentNode/@id !=''">  
    <li>
    <href="{umbraco.library:NiceUrl($currentNode/@id)}"><xsl:value-of select="$currentNode/@nodeName"/></a>
    </li>
    </xsl:if>
      
    </xsl:for-each>

    Rich

  • Phil Crowe 192 posts 256 karma points
    Oct 25, 2010 @ 09:30
    Phil Crowe
    0

    Hi Rich. Tried this as soon as i got in work. Does exactly what i needed! thanks

Please Sign in or register to post replies

Write your reply to:

Draft