<xsl:template match="video[@youtube|@youtubeplaylist]" mode="youtube-view-url">
<xsl:variable name="youtube">
<xsl:choose>
<xsl:when test="@youtubeplaylist">
<xsl:value-of select="normalize-space(@youtubeplaylist)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(str:replace(@youtube, ',', ' '))" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="@youtubeplaylist">
<xsl:value-of select="$youtube" />
</xsl:when>
<xsl:when test="contains($youtube, ' ')">
<xsl:text>watch_videos?video_ids=</xsl:text>
<xsl:value-of select="str:replace($youtube, ' ', ',')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$youtube" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- QR code only for videos (no thumbnail) -->
<xsl:template match="video" mode="representations">
<xsl:variable name="the-url">
<xsl:apply-templates select="." mode="static-url"/>
</xsl:variable>
<xsl:variable name="youtube">
<xsl:choose>
<xsl:when test="@youtubeplaylist">
<xsl:value-of select="normalize-space(@youtubeplaylist)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(str:replace(@youtube, ',', ' '))" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<stack>
<!-- 2023-02-07: wrapping in a URL failed -->
<!-- for a LaTeX build of the sample article -->
<image>
<xsl:attribute name="pi:generated">
<xsl:text>qrcode/</xsl:text>
<xsl:apply-templates select="." mode="visible-id-early"/>
<xsl:text>.png</xsl:text>
</xsl:attribute>
</image>
<p>
<url>
<xsl:attribute name="href">
<xsl:apply-templates select="." mode="static-url"/>
</xsl:attribute>
<!-- Kill the automatic footnote -->
<xsl:attribute name="visual"/>
<!-- <xsl:text>Interactive</xsl:text> -->
<xsl:value-of select="$youtube" />
</url>
</p>
</stack>
</xsl:template>
<!-- video solutions go in the margin -->
<xsl:template match="solution[descendant::video and not(descendant::figure)]">
<xsl:param name="b-original" />
<xsl:param name="purpose" />
<xsl:param name="b-component-heading"/>
<xsl:text>\tcbmarginbox{%
</xsl:text>
<xsl:apply-templates select="." mode="solution-heading">
<xsl:with-param name="b-original" select="$b-original" />
<xsl:with-param name="purpose" select="$purpose" />
<xsl:with-param name="b-component-heading" select="$b-component-heading"/>
</xsl:apply-templates>
<xsl:apply-templates>
<xsl:with-param name="b-original" select="$b-original" />
</xsl:apply-templates>
<xsl:text>}{0cm}%
</xsl:text>
<xsl:text>
</xsl:text>
</xsl:template>