模板应该匹配所有元素 "b" 至少有一个祖先 "a"

template should match all elements "b" which have at least one ancestor "a"

<xsl:template match="//a//b">...</xsl:template>

几乎可以满足我的要求。但它不 select 例如这个:(b 在 b 的内部,在 a 的内部)

<x>
   <y>
      <a>
         <b>
            <b>THIS</b>
         </b>
      </a>
   </y>
</x>

谁有想法?

我试过了,有什么相同之处:

<xsl:template match="//b[ancestor::a]">

it does not select for example this one: (b's inside b's inside a's)

首先,匹配不匹配select。因此,// 前缀对 match 模式没有任何作用。无论如何,所有这些匹配模式:

match="//a//b"
match="a//b"
match="//b[ancestor::a]">
match="b[ancestor::a]">

将匹配您示例中的 两个 b 元素。如果您发现其他东西,请检查您的方法:很可能,您的模板没有应用任何模板 - 因此处理器永远不会到达内部 b