【发布时间】:2019-01-10 11:51:45
【问题描述】:
我有以下结构的xml文件
<abc:element name="Super A">
...(some of other tags)
<abc:element name="A">
...(some of other tags)
<abc:element name="1A">
...(some of other tags)
<abc:element name="ABC">
<abc:docs>
<abc:text>
Some text
</abc:text>
</abc:docs>
</abc:element>
...(some of other tags)
</abc:element>
...(some of other tags)
</abc:element>
...(some of other tags)
</abc:element>
我在 abc:element name="ABC"> 节点中,我只想获取带有标签 <abc:element> 的最近祖先。在上面的例子中是<abc:element name="1A">。我尝试了一些方法,但都没有返回预期的结果。示例我尝试使用这个:<xsl:value-of select="ancestor::abc:element[1]"/> 但这不仅返回最近的所有元素。如何得到我预期的结果?在 xslt 中可以吗?
【问题讨论】:
-
您能否编辑您的帖子,向我们展示最小但完整的 XML、XSLT 示例、您想要的输出以及您收集到的关于您使用哪个软件运行它的信息?路径
ancestor::abc:element[1]乍一看是对的,不知道哪里出了问题。 -
您的问题无法从您的描述中重现:请参阅:xsltransform.hikmatu.com/bFDb2BS/1 所以您必须做一些与您描述的不同的事情。
-
我的例子中的属性“name”只是为了简化描述我的问题而添加的。我只知道我在
<abc:element>标签中,我想去最近的祖先标签<abc:element> -
MY例子中的
name属性用来说明选择正确。