我的输入XML就像下面的部分一样。
<part type="backmatter">
<section counter="yes" level="1">
<title>Credits<target id="page1301"/></title>
<section counter="yes" level="2">
<title>Chapter 1</title>
<para><link idref="c001_t003">Table 1-3</link> Adapted from Sidle DM</para>
......
......
</section>
</section>
<section counter="yes" level="1">
<title>Index<target id="page1321"/></title>
<section counter="yes" level="2">
<title>A</title>
<listing type="dash">
<litem><para>Abbé lip switch flap</para>
</litem>
<litem><para>Abdomen</para>
......
......
</section>
</section>
</part>
输出应该是,
<part type="backmatter">
<section counter="yes" level="1">
<title>Credits<target id="page1301"/></title>
<section counter="yes" level="2">
<title>Chapter 1</title>
<para><link idref="c001_t003">Table 1-3</link> Adapted from Sidle DM</para>
......
......
</section>
</section>
<!--<section counter="yes" level="1">
<title>Index<target id="page1321"/></title>
<section counter="yes" level="2">
<title>A</title>
<listing type="dash">
<litem>
<para>Abbé lip switch flap</para></litem>
<litem><para>Abdomen</para>
......
......
</section>
</section>-->
</part>
我的xslt是,
<xsl:template match="section">
<xsl:choose>
<xsl:when test="following-sibling::title[contains(., 'Index')]">
<xsl:text disable-output-escaping="yes"><!--</xsl:text>
<xsl:copy><xsl:apply-templates select="node() | @*"/> </xsl:copy>
<xsl:text disable-output-escaping="yes">--></xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:copy><xsl:apply-templates select="node() | @*"/> </xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
我想评论&#34;部分&#34;每当标题包含&#39;索引&#39;字符串和其余部分应该是在xml中。能否帮助我们解决这个问题。
答案 0 :(得分:2)
它几乎可以工作,你只需稍微改变你的状况:
<xsl:choose>
<xsl:when test="contains(title, 'Index')">
<xsl:text disable-output-escaping="yes"><!--</xsl:text>
<xsl:copy><xsl:apply-templates select="node() | @*"/></xsl:copy>
<xsl:text disable-output-escaping="yes">--></xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:copy><xsl:apply-templates select="node() | @*"/></xsl:copy>
</xsl:otherwise>
</xsl:choose>