【问题标题】:XSLT: Remove nodes with empty specific grandchildXSLT:删除具有空特定孙子的节点
【发布时间】:2019-05-22 00:40:39
【问题描述】:

我正在尝试使用 XSLT 从 XML 中删除一些节点。

转换部分如下所示:

<xsl:template match="gmd:date[gmd:CI_Date/gmd:date/gco:DateTime = null]" />

...XML 看起来像这样:

<gmd:MD_Metadata ... >
  ...
  <gmd:identificationInfo>
    <gmd:MD_DataIdentification>
      <gmd:citation>
        <gmd:CI_Citation>
          ...
          <gmd:date>
            <gmd:CI_Date>
              <gmd:date>
                <gco:DateTime />
              </gmd:date>
              ...
            </gmd:CI_Date>
          </gmd:date>
          ...
        </gmd:CI_Citation>
        ...
      </gmd:citation>
    </gmd:MD_DataIdentification>
  </gmd:identificationInfo>
</gmd:MD_Metadata>

根据我对 XSLT 的了解(虽然不多),转换应该与空的 grand-grandchild 匹配。 但事实并非如此。 模板不匹配,转换什么也不做。 我尝试了各种方法(将其与 0 匹配、默认日期时间、与 text() 进行比较)......没有任何效果。

有什么线索吗?

【问题讨论】:

    标签: c# xml xslt geonetwork


    【解决方案1】:

    XSLT 中没有 null
    一个节点(一个文本值是一个节点)要么是空的,要么不存在。

    这里是空的。
    所以检查一个空值:

    <xsl:template match="gmd:date[gmd:CI_Date/gmd:date/gco:DateTime = '']" />
    

    如果gco:DateTime 没有价值,现在你的gmd:date 应该消失了。

    【讨论】:

    • 哈!伟大的!我的出发点是错误的 - 找到了一个首先使用 null 的答案,然后......好吧,你知道其余的。
    猜你喜欢
    • 2022-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    • 2017-12-07
    相关资源
    最近更新 更多