gpt4 book ai didi

xslt - 如何使用xslt选择节点的祖 parent

转载 作者:行者123 更新时间:2023-12-03 15:25:10 25 4
gpt4 key购买 nike

我处于只能测试子节点的情况,但是我必须将标签应用于该子节点的祖 parent 。

我试过使用:

<xsl:call-template name="grandparent" select="parent::parent::node()"/>

和:
<xsl:call-template name="grandparent" select="ancestor::node [@nameofgrandparentnode]"/>

但是两者都不起作用。

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

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

xslt select grandparent node depending on an attribute value of its grandchild node

使用下面的建议选择节点是可行的。谢谢!但是,我还需要通过祖 parent 或孙节点的属性进行测试。

我试过了:
<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>

但是,始终会调用模板“two”,并始终插入“”。即使对于属性值不等于“attrValue”的孙节点。

我在这里想念什么吗?

最佳答案

I've tried using:

<xsl:call-template name="grandparent" select="parent::parent::node()"/> 

and:

<xsl:call-template name="grandparent" select="ancestor::node[@nameofgrandparentnode]"/>

But neither works.



当然,它不会“起作用”,因为 <xsl:call-template>指令没有 select属性!

您可以使用 <xsl:with-param>指令的 <xsl:call-template>子代传递参数,如下所示:
<xsl:call-template name="compute">
<xsl:param name="pAncestor" select="someExpression"/>
</xsl:call-template>

对于select<xsl:with-param>属性,请使用:

对于真正的祖 parent :
../..

名称为 someName的最接近的祖先元素:
ancestor::someName[1]

对于名称最接近的祖先元素,其名称包含在变量 $ancName中:
ancestor::*[name()=$ancName][1]

关于xslt - 如何使用xslt选择节点的祖 parent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3672992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com