输入xml就像,
<figure counter="yes">
<legend><para><target id="c001_f004"/>One such example is glycogen, a branched polymer of glucose molecules.</para></legend>
<legend><para><emph type="bold">A</emph> Monosaccharides</para></legend>
<legend><para><emph type="bold">B</emph> Disaccharides: sucrose</para></legend>
<legend><para><emph type="bold">C</emph> Oligosaccharides</para></legend>
<legend><para><emph type="bold">D</emph> Polysaccharides: glycogen</para></legend>
<subfigure>
<graphic position="center" fileref="images/9781604063172_c001_f004a.jpg"/>
</subfigure>
<subfigure>
<graphic position="center" fileref="images/9781604063172_c001_f004b.jpg"/>
</subfigure>
<subfigure>
<graphic position="center" fileref="images/9781604063172_c001_f004c.jpg"/>
</subfigure>
<subfigure>
<graphic position="center" fileref="images/9781604063172_c001_f004d.jpg"/>
</subfigure>
</figure>
输出应该是,
<figure counter="yes">
<legend>
<para><target id="c001_f004"/>One such example is glycogen, a branched polymer of glucose molecules.</para>
<para><emph type="bold">A</emph> Monosaccharides</para>
<para><emph type="bold">B</emph> Disaccharides: sucrose</para>
<para><emph type="bold">C</emph> Oligosaccharides</para>
<para><emph type="bold">D</emph> Polysaccharides: glycogen</para>
</legend>
<subfigure>
<graphic position="center" fileref="images/9781604063172_c001_f004a.jpg"/>
</subfigure>
<subfigure>
<graphic position="center" fileref="images/9781604063172_c001_f004b.jpg"/>
</subfigure>
<subfigure>
<graphic position="center" fileref="images/9781604063172_c001_f004c.jpg"/>
</subfigure>
<subfigure>
<graphic position="center" fileref="images/9781604063172_c001_f004d.jpg"/>
</subfigure>
</figure>
我的XSLT如下所示,
<xsl:template match="legend">
<xsl:choose>
<xsl:when test="following-sibling::legend">
<xsl:apply-templates select="node() | @*"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
使用上面的XSLT时,我只能保留<para>
个元素内容。如果我手动添加<legend>
个元素,那么它会输出相同的输出。您能指导我们,如何一次性添加/保持<legend>
元素。