下面是我的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
$currentPageBranchVariable
is a variable for the second template which contains anItem
node.How would that be possible to get its parent element from there?
只需使用:
$currentPageBranchVariable/..
这会选择 $currentPageBranchVariable
中包含的所有节点(在本例中只有一个)的一组父节点(每个节点一个)。
关于xml - 如何获取当前节点变量的父节点元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8940871/