Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml Xpath-选择和读取所有子节点的值,而不考虑名称_Xml_Xpath_Xslt 2.0_Geonetwork - Fatal编程技术网

Xml Xpath-选择和读取所有子节点的值,而不考虑名称

Xml Xpath-选择和读取所有子节点的值,而不考虑名称,xml,xpath,xslt-2.0,geonetwork,Xml,Xpath,Xslt 2.0,Geonetwork,我正在进行xsl转换,将ISO 19139-2(2009)XML文档转换为一些文本字符串(GeoNetwork模式插件的索引字段/index.xsl,由ElasticSearch实例读取)。在特定元素中,我试图: 选择具有特定确切节点名称的该节点的所有子体 获取上述节点的所有立即子节点,具有特定名称的子节点除外 打印上述节点的名称和值 然而,我似乎从未从转换中获得任何输出。从其他例子来看,我觉得我肯定遗漏了一些非常简单的东西,但我不能完全指出 我尝试了几种不同的方法,主要围绕无名称空间节点的放置

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

  • 选择具有特定确切节点名称的该节点的所有子体
  • 获取上述节点的所有立即子节点,具有特定名称的子节点除外
  • 打印上述节点的名称和值
  • 然而,我似乎从未从转换中获得任何输出。从其他例子来看,我觉得我肯定遗漏了一些非常简单的东西,但我不能完全指出

    我尝试了几种不同的方法,主要围绕无名称空间节点的放置方式、我对某些路径的具体程度以及period/current node position元素的使用

    据我所知,我正在选择所有可用的MI_AcquisitionInformation,然后从中查找具有指定名称的子节点,然后获取它们的子节点,并应用特定的名称条件,然后读取这些节点的值及其名称。但是我什么也得不到

    <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>
    
    
    gmi:标识符:(来自其子节点的附加内容)
    gmi:引文:(来自其子节点的附加内容)
    gmi:状态:(不确定?可能什么都没有,因为值在这里的属性中?)
    gmi:标识符:(用于操作内部的标识符)
    gmi:说明:(适用于操作内部)
    gmi:标识符:(用于MI_AcquisitionInformation内部的标识符)
    gmi:说明:(适用于MI_AcquisitionInformation内的信息)
    gmi:标识符:(用于MI_AcquisitionInformation内部的标识符)
    gmi:类型:(用于MI_AcquisitionInformation中的一个)
    对于操作中的一个内部平台,与上面相同的信息。。。
    对于平台内部的MI_AcquisitionInformation,与上面相同的信息类型。。。
    
    大多数情况下,对于包含MI_操作、MI_平台和/或MI_工具的记录,我希望在ElasticSearch中看到名为(某物)细节的内容,但这需要经过另一个处理步骤


    但正如前面提到的,我什么也没有得到,也没有错误消息——因此我可能只是在错误的节点上选择,而不是在代码中实际出错。

    拼写错误修复和我昨晚意识到的更好的方法相结合似乎是解决方案。很抱歉,这不是一个完整的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中使用它的人,我把它直接放在gmd:distributionInfo一节下面(从第
    行开始考虑发布最小但完整的示例,在没有名称空间声明的情况下用XML或XSLT向我们显示名称空间前缀是没有意义的。我同意@MartinHonnen,但请注意,
    xsl for each
    应该是
    xsl:for each
    @kjhughes-ack,谢谢您的帮助。我也意识到了这一点我的代码不太理想。我会尝试一些东西,然后编辑问题。回复:虽然很简单,但完整,抱歉,我认为这对于问题来说已经足够完整了。我会稍微扩展一下示例。