我有这个输入:
<root>
<sector>
<nodeA id="a">
<section id="i">
<item1 id="1" method="delete"/>
<item1 id="1" method="create">
<somechild>a</somechild>
</item1>
<item1 id="1" method="change">
<somechild>a</somechild>
</item1>
</section>
<section id="i">
<item1 id="1" method="change">
<somechild>a</somechild>
</item1>
</section>
<section id="i">
<item1 id="1" method="delete"/>
<item1 id="1" method="create">
<somechild>a</somechild>
</item1>
</section>
</nodeA>
</sector>
</root>
我的 XSL 是:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*[not(.//*[@id!=''])][@method='delete']">
<xsl:if test="not(following::*[not(.//*[@id!=''])][@id=current()/@id][../@id = current()/../@id][generate-id(../..) = generate-id(current()/../..)])"/>
</xsl:template>
<xsl:template match="*[not(.//*[@id!=''])][@method!='delete']">
<xsl:if test="not(following::*[not(.//*[@id!=''])][@method='delete'][@id=current()/@id][../@id = current()/../@id][generate-id(../..) = generate-id(current()/../..)])"/>
</xsl:template>
<xsl:template match="@*|node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我的输出:
<root>
<sector>
<nodeA id="a">
<section id="i">
</section>
<section id="i">
</section>
<section id="i">
</section>
</nodeA>
</sector>
</root>
预期输出:
<root>
<sector>
<nodeA id="a">
<section id="i">
<item1 id="1" method="delete"/> <!-- leave this node -->
</section>
<section id="i">
</section>
<section id="i">
<item1 id="1" method="create"> <!-- leave this node -->
<somechild>a</somechild>
</item1>
</section>
</nodeA>
</sector>
</root>
这个想法是我想删除元素节点的组合
- 一种方法创建,然后是一种或多种修改,然后是一种删除方法,其余的保持不变。
- 例如,它必须是相同的元素名称,
<item1>
并且@id
在相同的父级下<section id=1>
。
任何人都可以帮助我进行转型吗?
谢谢。约翰