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

标签 xml xslt xpath parent

下面是我的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 an Item node.

How would that be possible to get its parent element from there?

只需使用:

$currentPageBranchVariable/..

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

关于xml - 如何获取当前节点变量的父节点元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8940871/

相关文章:

xml - 在基于 XSL 的转换后删除空的 xmlns 元素

XSLT 从 SOAP 消息正文获取 XML

c# - 正确的 XPath 会产生空结果

在运行时提取字段值的 Java 服务

python - Python 中 xml.dom.minidom 的空文本节点问题

xml - 按 XML 属性过滤 for-each

xml - 如何使用 HttpListener 接收包含 XML 的 HTTP Post

xml - XPath-选择一个名称相同的所有子节点本身都具有特定子节点的节点

xml - 如何输出xls中的所有xml?

html - 无法在 Scrapy 中使用 XPath 访问 HTML 元素