<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ssml="http://www.w3.org/2001/10/synthesis" version="2.0" exclude-result-prefixes="#all">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[@epub:type/tokenize(.,'\s+')='pagebreak' or @role='doc-pagebreak'] [not(*|text()[normalize-space(.)])]">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:value-of select="(@aria-label,@title)[1]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="html:*[@ssml:ph]">
<xsl:param name="alphabet" tunnel="yes" as="xs:string?" select="()"/>
<xsl:if test="*[not(self::html:span[@role='word'])] or (html:span[@role='word'] and text()[string()]) or count(html:span[@role='word'])>1 or html:span[@role='word']/(@* except @role) or html:span[@role='word']/*">
<xsl:message terminate="yes">
<xsl:text>An element with a ssml:ph attribute that contains anything else than a text node </xsl:text>
<xsl:text>consisting of a single word is not supported. Got: </xsl:text>
<xsl:value-of select="."/>.</xsl:message>
</xsl:if>
<xsl:if test="not(exists($alphabet))">
<xsl:message terminate="yes">No alphabet defined for <xsl:value-of select="."/>.</xsl:message>
</xsl:if>
<xsl:variable name="phoneme" as="element(ssml:phoneme)">
<ssml:phoneme>
<xsl:attribute name="alphabet" select="$alphabet"/>
<xsl:attribute name="ph" select="@ssml:ph"/>
<xsl:sequence select="text()|html:span[@role='word']/text()"/>
</ssml:phoneme>
</xsl:variable>
<xsl:variable name="word">
<xsl:choose>
<xsl:when test="html:span[@role='word']">
<xsl:for-each select="html:span[@role='word']">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:sequence select="$phoneme"/>
</xsl:copy>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="$phoneme"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="@* except @ssml:ph">
<xsl:copy>
<xsl:apply-templates select="@* except @ssml:ph"/>
<xsl:sequence select="$word"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="$word"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*[@ssml:alphabet]" priority="5">
<xsl:next-match>
<xsl:with-param name="alphabet" tunnel="yes" select="@ssml:alphabet"/>
</xsl:next-match>
</xsl:template>
<xsl:template match="@ssml:alphabet"/>
</xsl:stylesheet>