【发布时间】:2017-10-23 21:51:54
【问题描述】:
我是 xslt 的新手,遇到了一个非常棘手的组合并案例。我有以下 xml 结构:
<root>
<section name="A">
<table name="B">
<row1/>
</table>
</section>
<section name="A">
<table name="B">
<row1/>
</table>
</section>
<section name="A">
<table name="B">
<row1/>
</table>
<section name="C"></section>
</section>
<section name="A">
<table name="B">
<row1/>
</table>
</section>
<section name="A">
<table name="B">
<row1/>
</table>
</section>
</root>
我需要以某种方式对其进行转换,以使代码只合并 row1 直到它遇到一个包含名称为 c 的子节的节:
<root>
<section name="A">
<table name="B">
<row1/>
<row1/>
</table>
</section>
<section name="A">
<table name="B">
<row1/>
</table>
<section name="C"></section>
</section>
<section name="A">
<table name="B">
<row1/>
<row1/>
</table>
</section>
</root>
到目前为止,我只是合并了所有部分中的所有行:
<xsl:template match="section[@name='A' and following-sibling::section[@name='A'] ]//table[1]" >
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="ancestor::section[@name='A']/following-sibling::section[@name='A']//table[1]/row1" />
</xsl:copy>
</xsl:template>
<xsl:template match="section[ @name='A' and preceding-sibling::section[@name='A'] ]//table[1]" />
请帮帮我。
【问题讨论】: