获取 XSL 中的父节点属性 [英] Getting the parent node attributes in XSL
本文介绍了获取 XSL 中的父节点属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 XML 中,我有以下内容:
In my XML I have the following:
<a>
<b>
<c something="false">
<d>
<e>
<f>someResult</f>
</e>
</d>
</c>
</b>
</a>
现在在循环中的 XSL 中,我可以执行以下操作:
Now in the XSL within a loop I can do the following:
<xsl:value-of select="f"></xsl:value-of>
但是如何在c中获取属性?
But how can I get the attribute in c?
我尝试过以下操作
<xsl:value-of select="////@something"></xsl:value-of>
以及尝试父母,但似乎没有任何效果.你能得到这样的父节点吗?
As well as trying parent and nothing seems to be working. Can you get parent nodes like this?
另外,我不能只做:
<xsl:value-of select="/a/b/c/@something"></xsl:value-of>
因为可以有多个 c.
推荐答案
要向上移动树,您可以在每个级别使用..",即在这种情况下可能是
To move up the tree you use ".." per level ie in this instance probably
select="../../../@something"
您也可以按名称选择祖先节点(大约)
You can also select an ancestor node by name (approx)
select="ancestor::c[1]/@something"
更多示例见http://www.stackoverflow.com/questions/3672992
这篇关于获取 XSL 中的父节点属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文