【问题标题】:Get para that doesn't have an immediate child获取没有直系子女的 para
【发布时间】:2022-01-08 02:43:35
【问题描述】:

我有以下 HTML。

区块 1:

<div>
  <p>
    <strong>1:11</strong>
  </p>
  <p>
    this is a content with <strong>strong content</strong> this is some extra data.
  </p>
</div>

第 2 块:

<div>
   <p>
    this is extra content
  </p>
</div>

第 3 块:

<div>
  <p>
    <strong>1:11</strong>
  </p>
  <p>
    this is content with this is some extra data.
  </p>
</div>

我想要一个 XSLT,它只检索第一个 p 节点,该节点没有任何 strong 作为直接子节点。

我想要的输出是

对于块 1 - 这是具有 强内容 的内容,这是一些额外的数据。 对于块 2,这工作正常 - 这是额外的内容 对于第 3 块,这工作正常 - 这是满足于这是一些额外的数据。

我尝试了以下 XSLT descendant::p[not(./strong)][1]。这不适用于块 1。我哪里出错了?

【问题讨论】:

    标签: xslt-2.0


    【解决方案1】:

    为了从漂亮打印中忽略纯空格 text() 节点,您可以查找第一个不是空格的 text()strong,然后测试它是否是 strong 元素:

    descendant::p[not((text()[normalize-space()]|strong)[1][self::strong])]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多