I would like to target the topicref > topic > topic and change the title with numbering.
I have the following dita map
Code:
<map>
<chapter>
<topicref href="ditafile1#topic1">
<topicref href="ditafile1#topic2">
<topicref href="ditafile1#topic3">
and so forth
</chapter>
<chapter>
<topicref href="ditafile2#topic2-1>
<topicref href="ditafile2#topic2-2>
and so forth
</chapter>
</map>
Dita file 1:
Code:
<topic>
<topic>
<title>Introduction</title>
</topic>
<topic id="topic1>
<title>Number 1</title>
</topic>
<topic id="topic2>
<title>Number 2</title>
</topic>
</topic>
Dita file 2
Code:
<topic>
<topic id="topic2-1">
<title>Number 2-1</title>
</topic>
<topic>
<title></title>
</topic>
<topic id="topic2-2">
<title>Number 2-2</title>
</topic>
</topic>
By default,
Code:
<xsl:template match="topic/topic/title">
<h2>
<xsl:value-of select="text()"/>
</h2>
</xsl:template>
If topicref id in href and topic topic id match, change the title, add a numbering 1.1.
Someone suggested this solution, but <xsl:template match="topicref[@href]"> causes some issue that stop all my other html files from generating.
Code:
<xsl:template match="/">
<xsl:apply-templates select="//topicref"/>
</xsl:template>
<xsl:template match="topicref[@href]">
<xsl:variable name="href" as="xs:string" select="string(@href)"/>
<xsl:variable name="topicFile" as="xs:string" select="substring-before($href,'#')"/>
<xsl:variable name="id" as="xs:string" select="substring-after($href,'#')"/>
<xsl:variable name="levelStr" as="xs:string">
<xsl:number level="multiple" count="chapter|topicref" format="1.1"/>
</xsl:variable>
<xsl:variable name="title" as="text()*">
<xsl:apply-templates select="document(concat(string(resolve-uri('.', static-base-uri())),$topicFile))//topic[string(@id) eq $id]/title"/>
</xsl:variable>
<xsl:value-of select="$levelStr"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$title"/>
<xsl:text>
</xsl:text>
</xsl:template>
Expected output (for the title):
<h2'>1.1 Number 1</h2> // ignore the ' <br/>
<h2'>1.2 Number 2</h2> // ignore the ' <br/>
<h2'>2.1 Number 2-1</h2> // ignore the ' <br/>
<h2'>2.2 Number 2-2</h2> // ignore the ' <br/>
Questions:
How to target for each topicref , the topic topic title change it add numbering infront.