<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dtb="http://www.daisy.org/z3986/2005/dtbook/" xmlns="http://www.daisy.org/z3986/2005/dtbook/" version="2.0" exclude-result-prefixes="dtb"> <xsl:include href="recursive-copy.xsl"/> <xsl:include href="output.xsl"/> <xsl:param name="titleValue"> <xsl:choose> <xsl:when test="string-length(normalize-space(//dtb:head/dtb:meta[@name='dc:Title']/@content))>0"> <xsl:value-of select="normalize-space(//dtb:head/dtb:meta[@name='dc:Title']/@content)"/> </xsl:when> <xsl:when test="string-length(normalize-space(//dtb:frontmatter//dtb:doctitle[1]))>0"> <xsl:value-of select="normalize-space(//dtb:frontmatter//dtb:doctitle[1])"/> </xsl:when> <xsl:when test="//dtb:h1"> <xsl:value-of select="normalize-space((//dtb:h1)[1])"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="normalize-space((//dtb:hd)[1])"/> </xsl:otherwise> </xsl:choose> </xsl:param> <xsl:template match="dtb:head"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:if test="count(dtb:meta[@name='dc:Title'])=0"> <xsl:message terminate="no">Adding dc:Title metadata element</xsl:message> <xsl:element name="meta" namespace="http://www.daisy.org/z3986/2005/dtbook/"> <xsl:attribute name="name"> <xsl:text>dc:Title</xsl:text> </xsl:attribute> <xsl:attribute name="content"> <xsl:value-of select="$titleValue"/> </xsl:attribute> </xsl:element> </xsl:if> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="dtb:frontmatter"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:if test="count(dtb:doctitle)=0"> <xsl:message terminate="no">Adding doctitle element in the frontmatter</xsl:message> <xsl:element name="doctitle" namespace="http://www.daisy.org/z3986/2005/dtbook/"> <xsl:value-of select="$titleValue"/> </xsl:element> </xsl:if> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="dtb:meta[@name='dc:Title' and normalize-space(@content)='']"> <xsl:message terminate="no">Adding value to empty dc:Title metadata element</xsl:message> <xsl:element name="meta" namespace="http://www.daisy.org/z3986/2005/dtbook/"> <xsl:attribute name="name"> <xsl:text>dc:Title</xsl:text> </xsl:attribute> <xsl:attribute name="content"> <xsl:value-of select="$titleValue"/> </xsl:attribute> </xsl:element> </xsl:template> <xsl:template match="dtb:frontmatter/dtb:doctitle[normalize-space(self::*)='']"> <xsl:message terminate="no">Adding value to empty doctitle element in the frontmatter</xsl:message> <xsl:element name="doctitle" namespace="http://www.daisy.org/z3986/2005/dtbook/"> <xsl:value-of select="$titleValue"/> </xsl:element> </xsl:template> </xsl:stylesheet>