Reputation: 1268
I have the following docbook xml file in version 5.
<?xml version="1.0" encoding="UTF-8"?>
<book version="5.0" xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude">
<info>
<title>Title1</title>
<cover>
<para>
<para>a paragraph</para>
</para>
</cover>
</info>
<!-- Part A -->
<part>
<title>Part A</title>
<chapter label="1">
<title role="HEAD-1">Chapter1 from PartA</title>
<para role="richtext">
<para role="richtext"> Text in paragraph </para>
</para>
</chapter>
<chapter label="2">
<title role="HEAD-1">Chapter2 from partA</title>
<para>Another paragraph</para>
</chapter>
</part>
<!-- Part B -->
<part>
<title>Part B</title>
<chapter label="1">
<title role="HEAD-1">Chapter1 from PartB</title>
<section>
<title role="HEAD-2">Section1 from Chapter1 of PartB</title>
<para>a paragraph <ulink url="http://alink2">a link2</ulink></para>
</section>
<section>
<title role="HEAD-2">Section2 from Chapter1 of PartB</title>
<para>a paragraph <ulink url="http://alink2">a link2</ulink></para>
</section>
</chapter>
</part>
</book>
I'm trying to convert it to html through xslt v3 and by modifying specific elements ( I have used the saxon xslt library for java) such as the title and the ulink, i.e.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:db="http://docbook.org/ns/docbook"
xmlns:m="http://docbook.org/ns/docbook/modes"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xsl xs db m h"
version="3.0">
<xsl:import href="https://cdn.docbook.org/release/xsltng/current/xslt/docbook.xsl" />
<xsl:template match="db:ulink" mode="m:docbook">
<xsl:variable name="url" select="@url"/>
<xsl:variable name="name" select="normalize-space(.)"/>
<a href="{$url}" title="{$name}">
<xsl:value-of select="$name" />
</a>
</xsl:template>
<xsl:template match="db:title" mode="m:docbook">
<xsl:variable name="header" select="@role"/>-->
<xsl:variable name="title" select="normalize-space(.)"/>
print something e.g. <xsl:value-of select="$title" />
</xsl:template>
</xsl:stylesheet>
The ulink works as expected however I can't get the title correctly. I have tried different paths but with no success. A similar question was here xsl:value-of not working but it didn't help in this case.
The output I get is
<nav xmlns="http://www.w3.org/1999/xhtml" class="top"></nav><main xmlns="http://www.w3.org/1999/xhtml">
<article class="book">
<header>
<h1>Title1</h1>
</header>
<article class="part">
<h1 class="title">Part A</h1>
<article id="R_part1" class="part">
<header>
<h1><span class="label">Part<span class="sep"> </span></span><span class="number">I<span class="sep">. </span></span>Part A</h1>
</header>
<div id="R_part1_ch1" class="chapter" db-label="1">
<header>
<h1><span class="label">Chapter<span class="sep"> </span></span><span class="number">1<span class="sep">. </span></span>Chapter1 from PartA</h1>
</header>
<p class="richtext">
<p class="richtext"> Text in paragraph </p>
</p>
</div>
<div id="R_part1_ch2" class="chapter" db-label="2">
<header>
<h1><span class="label">Chapter<span class="sep"> </span></span><span class="number">2<span class="sep">. </span></span>Chapter2 from partA</h1>
</header>
<p>Another paragraph</p>
</div>
</article>
</article>
<article class="part">
<h1 class="title">Part B</h1>
<article id="R_part2" class="part">
<header>
<h1><span class="label">Part<span class="sep"> </span></span><span class="number">II<span class="sep">. </span></span>Part B</h1>
</header>
<div id="R_part2_ch1" class="chapter" db-label="1">
<header>
<h1><span class="label">Chapter<span class="sep"> </span></span><span class="number">1<span class="sep">. </span></span>Chapter1 from PartB</h1>
</header>
<section id="R_part2_ch1_s1" class="section">
<header>
<h2><span class="number">1<span class="sep"> </span></span>Section1 from Chapter1 of PartB</h2>
</header>
<p>a paragraph <a href="http://alink2" title="a link2">a link2</a></p>
</section>
<section id="R_part2_ch1_s2" class="section">
<header>
<h2><span class="number">2<span class="sep"> </span></span>Section2 from Chapter1 of PartB</h2>
</header>
<p>a paragraph <a href="http://alink2" title="a link2">a link2</a></p>
</section>
</div>
</article>
</article>
</article>
</main><nav xmlns="http://www.w3.org/1999/xhtml" class="bottom"></nav>
Any ideas?
Upvotes: 0
Views: 116