+<xsl:template mode='article-info' match='/document/article/published'>
+ <p>
+ <xsl:text>Posted </xsl:text>
+ <xsl:value-of select='/document/article/published' />
+ <xsl:if test='/document/article/updated'>
+ <xsl:if test='/document/article/updated != /document/article/published'>
+ <xsl:text>, last updated </xsl:text>
+ <xsl:value-of select='/document/article/updated' />
+ </xsl:if>
+ </xsl:if>
+ </p>
+</xsl:template>
+
+<xsl:template match='*[@article-info]' />
+<xsl:template mode='article-info' match='*[@article-info]'>
+ <xsl:copy>
+ <xsl:apply-templates select='@*[local-name() != "article-info"]' />
+ <xsl:apply-templates select='node()' />
+ </xsl:copy>
+</xsl:template>
+
+<xsl:template name='imgpara' match='xhtml:p[count(*)=1]
+ [normalize-space(text())=""]
+ [descendant::xhtml:img]'>
+ <xsl:copy>
+ <xsl:apply-templates select='@*[local-name() != "class"]' />
+ <xsl:attribute name='class'>
+ <xsl:if test='@class'>
+ <xsl:value-of select='concat(@class, " ")' />
+ </xsl:if>
+ <xsl:text>img</xsl:text>
+ </xsl:attribute>
+ <xsl:apply-templates select='node()' />
+ </xsl:copy>
+</xsl:template>
+
+<xsl:key name='gallery'
+ match='xhtml:html/xhtml:p[descendant::*[@generate-gallery]]'
+ use='generate-id(
+ ( ( preceding-sibling::*[not(descendant::*[@generate-gallery])][1]
+ /following-sibling::* ) | self::* ) [1])' />
+
+<xsl:template match='@generate-gallery' />
+<xsl:template match='xhtml:html/xhtml:p[descendant::*[@generate-gallery]]' />
+<xsl:template match='xhtml:html/xhtml:p[key("gallery", generate-id(.))]'>
+ <xsl:variable name='images' select='key("gallery", generate-id(.))' />
+ <xsl:choose>
+ <xsl:when test='count($images) > 1'>
+ <div>
+ <xsl:attribute name='class'>
+ <xsl:text>gallery</xsl:text>
+ <xsl:if test='//xhtml:a[f:contains-token(@class, "left")
+ or f:contains-token(@class, "right")]'>
+ <xsl:text> inline</xsl:text>
+ </xsl:if>
+ </xsl:attribute>
+ <xsl:for-each select='$images'>
+ <xsl:call-template name='imgpara' />
+ </xsl:for-each>
+ </div>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name='imgpara' />
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+