我有一个源 html 看起来像:
<p class="heading-8">Emergency Care<span class="char-style-override-68">, if not already done:</span></p>
<p class="List-Bullet-CHAM1-CHAM-1-List-Bullet-1 para-style-override-3"><span> </span><span class="char-style-override-25">1.</span><span> Do Initial Assessment (p. 72).</span></p>
现在我为 p 创建一个模板匹配:
<xsl:template match="x:p">
<xsl:choose>
<xsl:when test="contains(@class,'heading-8')">
<xsl:variable name="current-name" select="generate-id(.)"/>
<xsl:variable name="noTable" select="count(preceding-sibling::x:table)"/>
<p>
<b>
<xsl:apply-templates/>
</b>
</p>
<xsl:if test="following-sibling::*[1][self::x:p][contains(@class,'List-Bullet-CHAM1-CHAM-1')][generate-id(preceding-sibling::x:p[contains(@class,'heading-8 ')][1]) = $current-name]">
<ol>
<xsl:apply-templates select="following-sibling::x:p[contains(@class,'List-Bullet-CHAM1-CHAM-1')][count(preceding-sibling::x:table)=$noTable][generate-id(preceding-sibling::x:p[contains(@class,'heading-8 ')][1]) = $current-name]" mode="bullet"/>
</ol>
</xsl:if>
</xsl:when>
我现在遇到的问题是,我似乎永远无法进入那个内部 if 分支。但我认为源 html 与它完美匹配,只是不知道我可能错在哪里。
PS,我使用 generate-id() 函数来确定前面的兄弟节点的身份。