如果某个节点具有某个属性并且其父节点具有相同的属性,则匹配该节点? [英] Match a node if it has a certain attribute and its parent has the same attribute?
问题描述
好的,我有一个这样的查找辅助结构:
OK, I have a finding aid structure like so:
<c01 level="file">
<c02 level="file"></c02>
</c01>
对于我的 XSLT 模板,我希望能够只匹配具有 level="file" 属性的节点,这些节点的父节点也具有 level="file" 属性,以便我可以制定一些特定的格式在孩子身上.
For my XSLT template, I'd like to be able to match only nodes with the attribute of level="file" that have a parent also with the attribute of level="file" so that I can enact some specific formatting on the child.
通常匹配 level="file" 我只使用以下内容:
Normally to match level="file" I just use the following:
<xsl:template match="*[@level="file"]">
但是,出于格式化(缩进等)的目的,我需要将作为具有相同属性的节点的子节点的节点与其父节点区别对待.所以就像:
However, for the purposes of formatting (indentation, etc), I need the node that is a child of a node with the same attribute to be treated differently than its parent. So something like:
<xsl:template match="*[@level="file"] and parent::[@level="file"]">
有什么想法吗?我希望这是有道理的.谢谢!
Any ideas? I hope this makes sense. Thanks!
推荐答案
使用:
<xsl:template match="*[@level='file' ]/*[@level='file']">
该模板匹配level
属性的字符串值为"file"
并且是level 的字符串值的元素的子元素的任何元素
属性为 "file"
This template matches any element the string value of whose level
attribute is "file"
and that is a child of an element the string value of whose level
attribute is "file"
注意:没有使用..
或parent::
轴或//
,这是可能是最简单、最精确的匹配模式.
Do note: No ..
or parent::
axis or //
are used and this is probably the simplest and most precise match pattern.
这篇关于如果某个节点具有某个属性并且其父节点具有相同的属性,则匹配该节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!