in my XML I have a <chapter> root element. In this I have an <exercise> element and an <explanation> element. Each of these have child elements <heading> and <content>
I want my XSLT style sheet to process the heading and content elements the same regardless of where they are.
Ive done it by creating a template for //heading and //content.
But if I create anoter template for a parent of either of these, ( for exercise or explanation) then it overrides the earlier templates. How can I avoid this? I've tried assigning priorities but cant seem to get it right.
<xsl:template match="/">
<html>
<head>
<title>This is my first real try</title>
<link rel="stylesheet" href="try.css"/>
</head>
<body>
<h1>Chapter One</h1>
<xsl:apply-templates select="/chapter" />
</body>
</html>
</xsl:template>
<xsl:template match="//heading" >
<h2><xsl:apply-templates select="text()"/></h2>
</xsl:template>
<xsl:template match="//content" >
<xsl:apply-templates select="text()"/>
</xsl:template>
<!--<xsl:template match="explanation" >
<xsl:if test="solution">
<b>this is the solution</b>
</xsl:if>
<xsl:apply-templates select="text()"/>
</xsl:template>-->
<xsl:template match="instruction" >
<ul>
<li>
<xsl:if test="step">
<b>hello</b>
</xsl:if>
<xsl:apply-templates select="text()"/>
</li>
</ul>
</xsl:template>
</xsl:stylesheet>
I want my XSLT style sheet to process the heading and content elements the same regardless of where they are.
Ive done it by creating a template for //heading and //content.
But if I create anoter template for a parent of either of these, ( for exercise or explanation) then it overrides the earlier templates. How can I avoid this? I've tried assigning priorities but cant seem to get it right.
<xsl:template match="/">
<html>
<head>
<title>This is my first real try</title>
<link rel="stylesheet" href="try.css"/>
</head>
<body>
<h1>Chapter One</h1>
<xsl:apply-templates select="/chapter" />
</body>
</html>
</xsl:template>
<xsl:template match="//heading" >
<h2><xsl:apply-templates select="text()"/></h2>
</xsl:template>
<xsl:template match="//content" >
<xsl:apply-templates select="text()"/>
</xsl:template>
<!--<xsl:template match="explanation" >
<xsl:if test="solution">
<b>this is the solution</b>
</xsl:if>
<xsl:apply-templates select="text()"/>
</xsl:template>-->
<xsl:template match="instruction" >
<ul>
<li>
<xsl:if test="step">
<b>hello</b>
</xsl:if>
<xsl:apply-templates select="text()"/>
</li>
</ul>
</xsl:template>
</xsl:stylesheet>