如何获取当前节点变量的父节点元素?
下面是我的 xslt:
<xsl:template match="/">
<xsl:call-template name="generateLinks">
<xsl:with-param name="currentPageBranchVariable" select="//Item[@CurrentPageBranch='true']"></xsl:with-param>
</xsl:call-template>
</xsl:template>
并且:
<xsl:template name="generateLinks">
<xsl:param name="currentPageBranchVariable"></xsl:param>
<xsl:value-of select="$currentPageBranchVariable/@FullName"/>
// how to get the parent node of $currentPageBranchVariable?
</xsl:template>
可以看出, $currentPageBranchVariable 是包含 Item 节点的第二个模板的变量。
如何从那里获取其父元素?
我尝试了以下方法,但没有成功:
<xsl:value-of select="../$currentPageBranchVariable/@FullName"/>
<xsl:value-of select="parent::node()/$currentPageBranchVariable/@FullName"/>
<xsl:value-of select="parent($currentPageBranchVariable)/@FullName"/>
希望问题很清楚。
也许我想做的事情是不可能的?
谢谢,
The below is my xslt:
<xsl:template match="/">
<xsl:call-template name="generateLinks">
<xsl:with-param name="currentPageBranchVariable" select="//Item[@CurrentPageBranch='true']"></xsl:with-param>
</xsl:call-template>
</xsl:template>
And:
<xsl:template name="generateLinks">
<xsl:param name="currentPageBranchVariable"></xsl:param>
<xsl:value-of select="$currentPageBranchVariable/@FullName"/>
// how to get the parent node of $currentPageBranchVariable?
</xsl:template>
As can be seen, the $currentPageBranchVariable is a variable for the second template which contains an Item node.
How would that be possible to get its parent element from there?
I tried the below but didn't work:
<xsl:value-of select="../$currentPageBranchVariable/@FullName"/>
<xsl:value-of select="parent::node()/$currentPageBranchVariable/@FullName"/>
<xsl:value-of select="parent($currentPageBranchVariable)/@FullName"/>
Hope the question is clear.
Maybe what I'm trying to do is not possible?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Just use:
这会选择
$currentPageBranchVariable
中包含的所有节点(在本例中只有一个)的父节点集(每个节点一个)。Just use:
this selects the set of parents (one each) of all nodes (in this case just one) contained in
$currentPageBranchVariable
.您将轴放置在错误的位置。
您的表达式选择了上下文节点的父级,而不是
$currentPageBranchVariable
。由于您从/
上的匹配调用了模板,因此没有父级可供选择@FullName
。您需要使用该变量后面而不是之前的父轴从
$currentPageBranchVariable
中选择父级。其中任何一个都会起作用。
You were putting the axis in the wrong spot.
Your expressions were selecting the parent of the context node, not the
$currentPageBranchVariable
. Since you called the template from a match on/
, there is no parent to select@FullName
from.You need to select the parent from the
$currentPageBranchVariable
by using the parent axis following that variable, not before.Either of these will work.