XSLT获得最后一个元素

编程入门 行业动态 更新时间:2024-10-07 22:30:13
本文介绍了XSLT获得最后一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图在xml中找到最后一个元素,

I am trying to find the last element in my xml, which looks like

<list> <element name="A" /> <element name="B" > <element name="C" /> <element name="D" > <element name="D" /> <element name="E" /> <element name="F" /> <element name="G" /> </element> <element name="H" /> <element name="I" /> </list>

我需要获取某种反向菜单,其中当前元素和父级突出显示为活动",而同级元素突出为不活动".取而代之的是,只有当我单击"D"元素时,我才会有一棵凌乱的树.

I need to get some kind of reverse menu, where current element and parents are highlighted as "active" and sibling as "inactive". Instead in result I have a messy tree only when I suppose "D" element clicked.

双重D元素是我的问题.当我使用 第一次选择首次出现 D元素时(调试器显示),select="//element[@name='D'][last()]"或select="//element[@name='D' and last()]"(正确的是吗?).这是xsl

Double D elements are my problem. When I use select="//element[@name='D'][last()]" or select="//element[@name='D' and last()]" (btw which one is correct?) first time first occurrence of D element is selected (debugger shows that). Here is xsl

<xsl:template match="list"> <xsl:apply-templates select="//navelement[@name = 'D'][last()]" mode="active"/> </xsl:template> <xsl:template match="element"> <ul class="menu"> <xsl:apply-templates select="preceding-sibling::node()" mode="inactive"/> <li><a>....</a></li> <xsl:apply-templates select="following-sibling::node()" mode="inactive"/> </ul> <xsl:apply-templates select="parent::element" mode="active"/> </xsl:template> <xsl:template match="element" mode="inactive"> <li><a>....</a></li> </xsl:template>

推荐答案

您需要将last()索引放在节点列表结果上,而不是作为选择标准的一部分.试试

You need to put the last() indexing on the nodelist result, rather than as part of the selection criteria. Try

(//element[@name='D'])[last()]

更多推荐

XSLT获得最后一个元素

本文发布于:2023-11-13 03:00:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583240.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   XSLT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!