尝试这个。这是我的示例 XML(我添加了一个根元素只是为了测试):
<root>
<CHAPT>
<CHAPTNO>1.1</CHAPTNO>
<SUBJ>Introduction1111</SUBJ>
<P>foo text</P>
<P>foo text</P>
</CHAPT>
<CHAPT>
<SUBJ>Introduction2222</SUBJ>
<P>foo text</P>
<P>foo text</P>
</CHAPT>
<CHAPT>
<CHAPTNO>3333</CHAPTNO>
<SUBJ>Introduction3333</SUBJ>
<P>foo text</P>
<P>foo text</P>
</CHAPT>
</root>
XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" indent="no"/>
<xsl:template match="/">
<xsl:for-each select="root/CHAPT">
<xsl:if test="SUBJ[count(../CHAPTNO)=1]">
<p class="chapheader">
<span class="chapnumbers"><xsl:value-of select="CHAPTNO"/></span>
<xsl:value-of select="SUBJ"/>
</p>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
结果输出:
<p class="chapheader"><span class="chapnumbers">1.1</span>Introduction1111</p>
<p class="chapheader"><span class="chapnumbers">3333</span>Introduction3333</p>