小编hig*_*all的帖子

如何使用xslt选择节点的祖父节点

我遇到的情况是我只能测试子节点,但是我必须将标签应用于这个子节点的祖父节点.

我尝试过使用:

<xsl:call-template name="grandparent" select="parent::parent::node()"/>
Run Code Online (Sandbox Code Playgroud)

和:

<xsl:call-template name="grandparent" select="ancestor::node [@nameofgrandparentnode]"/>
Run Code Online (Sandbox Code Playgroud)

但都不起作用.

祖父节点的级别不固定,所以我认为我也不能使用[@ level =#].任何关于如何选择它的想法将不胜感激.

编辑: - 此部分已作为新问题发布:

xslt根据其孙子节点的属性值选择祖父节点

使用下面的建议选择节点.谢谢!但是我还需要通过祖父母或孙子节点的属性进行测试.

我试过了:

<xsl:template name"one" match="grandparentnode">
 <Tag1>
  <xsl:apply-templates select="parentNode" />
 </Tag1>
</xsl:template>

<xsl:template name="two" match="grandparentnode[*/*/@grandchildattr='attrValue']">
 <Tag2>
     <xsl:apply-templates select="parentNode" />
 </Tag2>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

但是总是调用模板"two",并且始终插入"".即使对于属性值不等于'attrValue'的孙子节点也是如此.

我在这里错过了什么吗?

xslt select xpath

7
推荐指数
2
解决办法
3万
查看次数

标签 统计

select ×1

xpath ×1

xslt ×1