2

我有看起来像的xml

<MeasureSet>
    <MeasureSetType val_type="name">Variant</MeasureSetType>
    <Measure>
      <MeasureType val_type="name">single nucleotide variant</MeasureType>
      <AttributeSet>
        <MeasureAttributeType val_type="name">HGVS</MeasureAttributeType>
        <Attribute>NM_000054.4:c.838dupT</Attribute>
      </AttributeSet>
      <Citation>
        <CitationType val_type="name">general</CitationType>
        <ID Source="PubMed">10820168</ID>
      </Citation>
      <Citation>
        <CitationType val_type="name">general</CitationType>
        <ID Source="PubMed" />
      </Citation>
      <Citation>
        <CitationType val_type="name">general</CitationType>
        <ID Source="PubMed">9773787</ID>
      </Citation>
      <Citation>
        <CitationType val_type="name">general</CitationType>
        <ID Source="PubMed">18726898</ID>
      </Citation>
      <Citation>
        <CitationType val_type="name">general</CitationType>
        <ID Source="PubMed" />
      </Citation>
    </Measure>
  </MeasureSet>

我想删除具有 Citation/ID/@Source = "PubMed" 且 Citation/ID 为空的 Citation 元素节点

这只会删除 ID 元素,但会删除正确的元素

SET @myBlob.modify('delete //Citation/ID[@Source = ''PubMed''
      and string-length(string(number(.))) = 0]') 

这会删除所有引文元素

SET @myBlob.modify('delete //Citation[ID/@Source = ''PubMed''
      and string-length(string(number(.))) = 0]') 

似乎应该有一个我没有想到的简单解决方案。有什么建议么?谢谢

4

1 回答 1

2

您的第二个是检查错误元素的长度 - 它正在查看(.),这是Citation元素(因为它位于Citation元素的谓词中)。改为使用

SET @myBlob.modify('
      delete //Citation[ID/@Source = ''PubMed'' 
                        and string-length(string(number(ID[1]))) = 0]') 

我已更改.ID[1]. [1]是必需的,因为“ 'number()' requires a singleton (or empty sequence)”。

于 2013-01-11T12:53:45.397 回答