本文介绍了获取当前节点 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
发布评论