Xpath - 选择和读取所有 children 节点的值,无论名称如何

Xpath - selecting and reading value of all children nodes, regardless of name

我正在进行 xsl 转换,将 ISO 19139-2 (2009) XML 文档转换为一些文本字符串(GeoNetwork 模式插件的 index-fields/index.xsl ,然后由 ElasticSearch 实例读取)。在特定元素中,我试图:

  1. select 该节点的所有 后代 具有特定的确切节点名称
  2. 获取上述节点的所有 立即 children 除了具有特定名称的节点
  3. 打印上述节点的名称和值

但是,我似乎从来没有从转换中得到任何输出。从其他例子来看,我觉得我一定遗漏了一些非常简单的东西,但我不能完全理解它。

我尝试了几种不同的方法,主要围绕 no-namespace 节点的放置方式、我对某些路径的具体程度以及 period/current 节点位置元素的使用。

据我所知,我正在 select 搜索所有可用的 MI_AcquisitionInformation,然后从那里寻找具有指定名称的 children,然后获取他们的 children,加上应用特定的名称条件,然后读出那些节点的值和它们的名称。但是我什么也没得到。

<xsl-for-each select="gmi:acquisitionInformation/*">            
  <xsl:for-each select=".//gmi:MI_Operation/*[name() != 'gmi:platform']">
    <operationDetails> <!-- lines like this, without a namespace, end up being the name of the 'bundle' holding the resulting output' -->
      <xsl:value-of select="name()"/>:<xsl:value-of select="."/>
    </operationDetails>
  </xsl:for-each>       

  <xsl:for-each select=".//gmi:MI_Platform/*[name() != 'gmi:instrument']">
    <platformDetails>
      <xsl:value-of select="name()"/>:<xsl:value-of select="."/>
    </platformDetails>
  </xsl:for-each>        

  <xsl:for-each select=".//gmi:MI_Instrument">
    <instrumentDetails>
      <xsl:value-of select="name()"/>:<xsl:value-of select="."/>
    </instrumentDetails>
  </xsl:for-each>        
</xsl-for-each>

具体的详细示例是...

<gmi:acquisitionInformation>
  <gmi:MI_AcquisitionInformation>
    <gmi:instrument>
      <gmi:MI_Instrument>
        <gmi:identifier>
          (additional content in nodes)
        </gmi:identifier>
        <gmi:type>
          <gco:CharacterString> Text </gco:CharacterString>
        </gmi:type>
      </gmi:MI_Instrument>
    </gmi:instrument>
    <gmi:operation>
      <gmi:MI_Operation>
        <gmi:identifier>
          (additional content in nodes)
        </gmi:identifier>        
        <gmi:citation>
          (additional content in nodes)
        </gmi:citation>
        <gmi:status>
          <gmd:MD_ProgressCode (content in attributes)/>
        </gmi:status>
        <gmi:platform>
          <gmi:MI_Platform>
            <gmi:identifier>
              (additional content in nodes)
            </gmi:identifier>
            <gmi:description>
              <gco:CharacterString> Text </gco:CharacterString>
            </gmi:description>
            <gmi:instrument>
              <gmi:MI_Instrument>
                <gmi:identifier>
                  (additional content in nodes)
                </gmi:identifier>
                <gmi:type>
                  <gco:CharacterString> Text </gco:CharacterString>
                </gmi:type>
              </gmi:MI_Instrument>
            </gmi:instrument>
          </gmi:MI_Platform>
        </gmi:platform>
      </gmi:MI_Operation>
    </gmi:operation>
    <gmi:platform>
      <gmi:MI_Platform>
        <gmi:identifier>
          (additional content in nodes)
        </gmi:identifier>
        <gmi:description>
          <gco:CharacterString> Text </gco:CharacterString>
        </gmi:description>
        <gmi:instrument>
          <gmi:MI_Instrument>
            <gmi:identifier>
              (additional content in nodes)
            </gmi:identifier>
            <gmi:type>
              <gco:CharacterString> Text </gco:CharacterString>
            </gmi:type>
          </gmi:MI_Instrument>
        </gmi:instrument>
      </gmi:MI_Platform>
    </gmi:platform>
  </gmi:MI_AcquisitionInformation>
</gmi:acquisitionInformation>

我希望上面的示例是这样的。

<operationDetails>
  gmi:identifier:(the additional content from its child nodes)
  gmi:citation:(the additional content from its child nodes)
  gmi:status:(Unsure? maybe nothing because the values are in attributes here?)
<!-- note here that there is no platform information -->
</operationDetails>
<platformDetails>
  gmi:identifier:(for the one inside the operation)
  gmi:description:(for the one inside the operation)
</platformDetails>
<platformDetails>
  gmi:identifier:(for the one inside MI_AcquisitionInformation)
  gmi:description:(for the one inside MI_AcquisitionInformation)
<!-- note here that there is no instrument information -->
</platformDetails>
<instrumentDetails>
  gmi:identifier:(for the one inside MI_AcquisitionInformation)
  gmi:type:(for the one inside MI_AcquisitionInformation)
</instrumentDetails>
<instrumentDetails>
  for the one inside platform inside the operation, same sort of info as above...
</instrumentDetails>
<instrumentDetails>
  for the one inside the platform inside MI_AcquisitionInformation, same sort of info as above...
</instrumentDetails>

大多数情况下,对于包含 MI_Operation、MI_Platform、and/or MI_Instrument 的记录,我希望在 ElasticSearch 中看到名为 (something)Details 的内容,但那是经过另一步处理。

但如前所述,我什么也没得到,也没有错误消息 - 所以大概我只是 select 在错误的节点上运行,而不是在代码中实际出错。

拼写错误修复和我昨晚意识到的更好的方法相结合似乎是解决方案。抱歉,这不是一个完整的 xsl 文档,但解决方案的要点是...

      <xsl:for-each select="gmi:acquisitionInformation/*">        
        <xsl:for-each select=".//gmi:MI_Operation">
          <operationDetails>{
            <xsl:for-each select="./*[name() != 'gmi:platform']">
              &quot;<xsl:value-of select="name()"/>&quot;:&quot;<xsl:value-of select="."/>&quot;,
            </xsl:for-each>
          }</operationDetails>
        </xsl:for-each>       

        <xsl:for-each select=".//gmi:MI_Platform">
          <platformDetails>{
            <xsl:for-each select="./*[name() != 'gmi:instrument']">
              &quot;<xsl:value-of select="name()"/>&quot;:&quot;<xsl:value-of select="."/>&quot;,
            </xsl:for-each>
          }</platformDetails>
        </xsl:for-each>        

       <xsl:for-each select=".//gmi:MI_Instrument">
          <instrumentDetails>{
            <xsl:for-each select="./*">
              &quot;<xsl:value-of select="name()"/>&quot;:&quot;<xsl:value-of select="."/>&quot;,
            </xsl:for-each>
          }</instrumentDetails>
        </xsl:for-each>      
      </xsl:for-each>

对于想在 GeoNetwork 中使用它的人,我将它直接放在我的模式插件 index-fields\index.xsl 中 gmd:distributionInfo 部分(从行 <xsl:for-each select="gmd:distributionInfo/*> 开始)下。这会在 gmi:MI_Metadata 中选取 gmi:acquisitionInformation 块,前提是您更改根模板匹配以适应 gmi:MI_Metadata