0

I have the following basic xml which I to parse to give the NAME only if none of the DB values = DB1.

<rnas>
  <rna ID="1">
    <NAME>Segment 6</NAME>
    <XREF>
      <ID>AF389120</ID>
      <DB>DB1</DB>
    </XREF>
    <XREF>
      <ID>ABCDE</ID>
      <DB>DB2</DB>
    </XREF>
  </rna>
  <rna ID="10">
    <NAME>Segment 3</NAME>
    <XREF>
      <ID>12345</ID>
      <DB>DB2</DB>
    </XREF>
    <XREF>
      <ID>66789</ID>
      <DB>DB3</DB>
    </XREF>
  </rna>
</rnas>

The expected output would be:

<rnas>
  <rna ID="10">
    <NAME>Segment 3</NAME>
  </rna>
<rnas>

I am still a relative newbie and have tried a variety of approaches using XSLT 2.0 but so far have not been able to get anything to work properly. Any help would be much appreciated.

4

1 回答 1

1

这会做你想做的

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="rna[.//DB/text()='DB1']"/>
  <xsl:template match="XREF"/>

</xsl:stylesheet>

这是一个身份转换以及两个空模板。第一个匹配任何rna包含 aDB和文本 value 的内容DB1,并禁止它。第二个匹配XREF您不想输出的所有元素。

于 2012-04-19T23:07:50.287 回答