获取当前节点 xpath

编程入门 行业动态 更新时间:2024-10-25 10:29:00
本文介绍了获取当前节点 xpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要获取我为其编写了 xsl 函数的当前节点的 xpath

I need to get the xpath of current node for which i have written an xsl function

<func:function name="fn:getXpath"> <xsl:variable name="xpath"> <xsl:for-each select="ancestor-or-self::*"> <xsl:value-of select="concat($xpath, name())" /> <xsl:if test="not(position()=last())"> <xsl:value-of select="concat('/', $xpath)" /> </xsl:if> </xsl:for-each> </xsl:variable> <func:result select="$xpath" /> </func:function>

但是当我运行这个时,我收到以下错误

But when I run this, I'm getting the following error

file:///D:/test.xsl; Line #165; Column #63; Variable accessed before it is bound! file:///D:/test.xsl; Line #165; Column #63; java.lang.NullPointerException

我使用的是 xalan 2.7.0.请帮忙.

I'm using xalan 2.7.0. Please help.

推荐答案

您在变量本身的定义中使用了变量 $xpath:

You are using the variable $xpath inside the definition of the variable itself:

<func:function name="fn:getXpath"> <xsl:variable name="xpath"> <xsl:for-each select="ancestor-or-self::*"> <xsl:value-of select="concat($xpath, name())" /> <------- <xsl:if test="not(position()=last())"> <xsl:value-of select="concat('/', $xpath)" /> <------- </xsl:if> </xsl:for-each> </xsl:variable> <func:result select="$xpath" /> </func:function>

此时变量未知.

更多推荐

获取当前节点 xpath

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

发布评论

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

>www.elefans.com

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