如何获取当前节点变量的父节点元素?

发布于 2024-12-27 22:40:27 字数 1058 浏览 2 评论 0原文

下面是我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小情绪 2025-01-03 22:40:27

$currentPageBranchVariable 是第二个模板的变量
其中包含一个 Item 节点。

如何从那里获取其父元素?

Just use

$currentPageBranchVariable/..

这会选择 $currentPageBranchVariable 中包含的所有节点(在本例中只有一个)的父节点集(每个节点一个)。

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?

Just use:

$currentPageBranchVariable/..

this selects the set of parents (one each) of all nodes (in this case just one) contained in $currentPageBranchVariable .

浮萍、无处依 2025-01-03 22:40:27

您将轴放置在错误的位置。

您的表达式选择了上下文节点的父级,而不是 $currentPageBranchVariable。由于您从 / 上的匹配调用了模板,因此没有父级可供选择 @FullName

您需要使用该变量后面而不是之前的父轴从 $currentPageBranchVariable 中选择父级。

其中任何一个都会起作用。

    <xsl:value-of select="$currentPageBranchVariable/../@FullName" />
    <xsl:value-of select="$currentPageBranchVariable/parent::*/@FullName" />

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.

    <xsl:value-of select="$currentPageBranchVariable/../@FullName" />
    <xsl:value-of select="$currentPageBranchVariable/parent::*/@FullName" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文