Xml 如何通过XSL删除一个重复的行?

Xml 如何通过XSL删除一个重复的行?,xml,xslt,Xml,Xslt,我有一个XML文件: <Picture id="001.png"/> <Line/> <Picture id="002.png"/> <Line/> <Picture id="003.png"/> 并希望将其更改为: <Picture id="001.png"/> <Line/> <Picture id="002.png"/> 我可以通过以下xsl删除“003.png”,因为我

我有一个XML文件:

<Picture id="001.png"/>

<Line/>

<Picture id="002.png"/>

<Line/>

<Picture id="003.png"/>

并希望将其更改为:

<Picture id="001.png"/>

<Line/>

<Picture id="002.png"/>

我可以通过以下xsl删除“003.png”,因为我知道它的id,但不知道如何删除它上面的“行”

 <xsl:template
     match="//Picture[@id='003.png']">
 </xsl:template>

我可以跟随兄弟姐妹吗?
非常感谢:)

您的输入不是格式良好的XML,因为它没有根元素,但这里有一个选项:

样式表

输入

输出
是的,您可以使用以下兄弟姐妹来完成。按如下所示更改来自Eero Helenius的代码

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
      <xsl:strip-space elements="*"/>

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

      <!--
      Drop unwanted elements: <Line> with fist following-sibling::Picture id = '003.png
      <Picture id="003.png"/>
      -->
      <xsl:template match="Picture[@id = '003.png']"/>

      <xsl:template match="Line">
          <xsl:if test="not(following-sibling::Picture[1][@id = '003.png'])">
            <xsl:copy>
              <xsl:apply-templates select="node() | @*"/>
            </xsl:copy>
        </xsl:if>
       </xsl:template>
    </xsl:stylesheet>


谢谢,但我不知道该“行”的索引,我知道的是该“行”在“003.png”之上。谢谢,我正在尝试以下代码:@iclinux:如果您真的使用上面的代码(match=“Line”模板中没有任何xsl:copy或其他输出语句,那么没有“行”就不足为奇了在输出中再添加标记。
<Elements>
  <Picture id="001.png"/>
  <Line/>
  <Picture id="002.png"/>
  <Line/>
  <Picture id="003.png"/>
</Elements>
<Elements>
  <Picture id="001.png"/>
  <Line/>
  <Picture id="002.png"/>
</Elements>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
      <xsl:strip-space elements="*"/>

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

      <!--
      Drop unwanted elements: <Line> with fist following-sibling::Picture id = '003.png
      <Picture id="003.png"/>
      -->
      <xsl:template match="Picture[@id = '003.png']"/>

      <xsl:template match="Line">
          <xsl:if test="not(following-sibling::Picture[1][@id = '003.png'])">
            <xsl:copy>
              <xsl:apply-templates select="node() | @*"/>
            </xsl:copy>
        </xsl:if>
       </xsl:template>
    </xsl:stylesheet>