I have a source html looks like:
<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>
Now I create a template match for 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>
The issue I am having now is that it seems that I could never get in to that inner if branch. But I think the source html matches perfectly with it, just don’t know where I could be wrong.
PS, I used generate-id() function to determine the identity of a preceding sibling node.
As far as I can see, the test condition of the xsl:if statement looks fine, except the trailing space in
contains(@class,'heading-8 '). There’s no class attribute that contains the string “heading-8 “. Removing the space in both the xsl:if and xsl:apply-templates elements should fix the issue.