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?
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.
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><a 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?
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?
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
Hi Rich, Can you give me an example of how i can 'split' them?
Sure
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>
<a href="{umbraco.library:NiceUrl(@id)}?categoryId=1">
<xsl:value-of select="@nodeName" />
</a>
</h2>
<xsl:for-each select="./* [@isDoc]">
<ul class="subCategoryListOnCategoryPage">
<li><a 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>
Which property holds the split ID's from your custom control in the above XSLT?
Rich
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><a 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?
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>
<a href="{umbraco.library:NiceUrl($currentNode/@id)}"><xsl:value-of select="$currentNode/@nodeName"/></a>
</li>
</xsl:if>
</xsl:for-each>
Rich
Hi Rich. Tried this as soon as i got in work. Does exactly what i needed! thanks
is working on a reply...