Level: Beginner
Goal: 1- Extract all Appendix Titles 2- If Appendix Title is Answer Key call custom solutions template 3. If Not Answer Key call default appendix template
XML:
<appendix>
<title>Appendix A</title>
<section>data</section>
</appendix>
<appendix>
<title>Answer Key</title>
<section>data</section>
</appendix>
XSLT:
<xsl:template match="appendix/title">
<xsl:choose>
<xsl:when test="self::node()[text()='Answer Key']">
<div class="answer-key">
<xsl:call-template name="solutions"/>
</div>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="appendix"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
This template works correctly; however I am interested in gaining some ground when it comes to writing solid xsl templates. Particularly the XPATH expressions. There seem to be various ways to achieve the same results when using XPath. Is the following XPath expression best?
test="self::node()[text()='Answer Key']"
Thanks ahead of time.