I'm a beginner in XSL and I'm trying to transform a Docbook document into an HTML one but I have a little problem.
I would like to select all the content of simplesect nodes included in a section but I would like to exclude the title of the first one.
The XML code is as follows:
<section xml:id="sectionid">
<title>Section title</title>
<simplesect>
<title>Title 1</title>
<para>My first text</para>
</simplesect>
<simplesect>
<title>Title 2</title>
<para>My second text</para>
</simplesect>
<simplesect>
<title>Title 3</title>
<para>My third text</para>
</simplesect>
</section>
The goal is to obtain this:
<h3>Section title</h3>
<p>My first text</p>
<h4>Title 2</h4>
<p>My second text</p>
<h4>Title 3</h4>
<p>My third text</p>
I have tried some things like these, included in an XSL stylesheet:
<xsl:template match="db:simplesect[position()>1]/db:title">
<h4><xsl:value-of select="text()" /></h4>
</xsl:template>
Associated with this to remove the title text from the output:
<xsl:template match="db:simplesect">
<xsl:apply-templates select="* except db:title" />
</xsl:template>
I have tried this too:
<xsl:template match="db:section/db:simplesect">
<h4><xsl:value-of select="db:title[not(parent::db:simplesect[position()=1])]" /></h4>
<xsl:apply-templates select="* except db:title" />
</xsl:template>
All of those failed.
I think I made mistakes in my xpath's requests and in the conditions/predicates in patterns. Could you help me to find the right patterns?
I would think that blocking that particular title from being processed with an empty template e.g.
<xsl:template match="simplesect[1]/title"/>(use a prefix if needed e.g.<xsl:template match="db:simplesect[1]/db:title"/>) is the easiest approach, together with templates that transform the rest to HTML e.g.<xsl:template match="simplesect/title"><h4><xsl:apply-templates/></h4></xsl:template>.