Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm trying to add class to my search results based on the results parent node id. I'm trying the following with no luck, any ideas?
<!-- add class based on site --> <xsl:if test="ancestor-or-self::node/@id = 1077"> <span class="myClass"> yeah! </span> </xsl:if>
Hi Amir,
If you're inside a for-each or a match template, do this:
<!-- Test a built-in attribute (works in both schemas) --> <xsl:if test="@parentID = 1077"> <span class="myClass">Yeah</span> </xsl:if> <!-- Test a custom property --> <xsl:if test="../header = 'My Header'"> <!-- do stuff --> </xsl:if> <!-- Test a custom property (old schema) --> <xsl:if test="../data[@alias = 'header'] = 'My Header'"> <!-- do stuff --> </xsl:if>
If you're inside the root template (match="/") you need to base the XPath off of $currentPage:
<xsl:if test="$currentPage/@parentID = 1077"> <!-- do stuff --> </xsl:if> <xsl:if test="$currentPage/../header = 'My Header'"> <!-- do stuff --> </xsl:if>
Hop that helps!
/Chriztian
Hi Chriztian, oddly this is only working for the first result? I'm adding it around line 350 inside this loop:
<xsl:for-each select="$matchedNodes">
I think I misunderstood you then - you're trying to check if a search result has a specific ancestor (not parent?) - in that case:
<xsl:for-each select="$matchedNodes"> <xsl:if test="ancestor::*[@id = 1077]"> <span class="myClass"> <!-- ... --> </span> <!-- ... --> </xsl:if> </xsl:for-each>
(works with both the old and the new schema, btw.)
- If the node being checked could itself be the node with id 1077, use the ancestor-or-self:: axis instead.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Add class based on parent node
I'm trying to add class to my search results based on the results parent node id. I'm trying the following with no luck, any ideas?
Hi Amir,
If you're inside a for-each or a match template, do this:
If you're inside the root template (match="/") you need to base the XPath off of $currentPage:
Hop that helps!
/Chriztian
Hi Chriztian, oddly this is only working for the first result? I'm adding it around line 350 inside this loop:
<xsl:for-each select="$matchedNodes">
Hi Amir,
I think I misunderstood you then - you're trying to check if a search result has a specific ancestor (not parent?) - in that case:
(works with both the old and the new schema, btw.)
- If the node being checked could itself be the node with id 1077, use the ancestor-or-self:: axis instead.
/Chriztian
is working on a reply...