想知道你是否可以帮我解决这个问题。
我正在循环浏览Sitecore中的项目,并在$products/item
中显示所有类别的轮播,模板为productcategory
。
我想添加一个突出显示当前项目类别的类,但无法确定如何获取祖先项目的keyvalueofparent
。
以下是我的问题代码段:
<ul>
<xsl:for-each select="$products/item[@template='productcategory']">
<li>
<xsl:attribute name="class">cat cat<xsl:value-of select="position()" />
<xsl:if test="./@key = 'keyvalueofparent'">active</xsl:if>
</xsl:attribute>
.
.
.
.
.
答案 0 :(得分:0)
以防其他人遇到此问题。与大多数事情一样,问题在于逻辑。
无论我尝试过什么而不是'keyvalueofparent'
,我都会被$products/item[@template='productcategory']
置于上下文中。
所以,为了解决这个问题,我需要做的就是在该上下文之外声明一个变量,这样它将引用当前项的父项:
<xsl:variable name="parentkey" select="../@key" />
然后继续在循环中使用变量:
<ul>
<xsl:for-each select="$products/item[@template='productcategory']">
<li>
<xsl:attribute name="class">
cat cat<xsl:value-of select="position()" />
<xsl:if test="./@key = $parentkey">
active
</xsl:if>
</xsl:attribute>