Horizontal rule splitter
Split a content block according to it's horizontal rule
Description
Sometimes you want to split the content provided by the author into 2 blocks.
This utility allows you to show content before a horizontal rule and after a horizontal rule individualy.
Example usage:
<xsl:apply-templates select="page-content/entry/content" mode="before-hr" />
<xsl:apply-templates select="page-content/entry/content" mode="after-hr" />
Note: This utility does not show anything if there is no horizontal rule. To detect something like that using a <choose>
:
<choose>
<xsl:when test="count(page-content/entry/content/hr) = 1">
<xsl:apply-templates select="page-content/entry/content" mode="before-hr" />
<xsl:apply-templates select="page-content/entry/content" mode="after-hr" />
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="page-content/entry/content/*" />
</xsl:otherwise>
</choose>
XSLT
View Raw
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Horizontal rule splitter ======================================================================== version: 1.00 author: Twisted website: www.twisted.nl ======================================================================== This utility allows you to show content before a horizontal rule and after a horizontal rule individualy. Example usage: <xsl:apply-templates select="page-content/entry/content" mode="before-hr" /> <xsl:apply-templates select="page-content/entry/content" mode="after-hr" /> Note: This utility does not show anything if there is no horizontal rule. To detect something like that using a <choose>: <choose> <xsl:when test="count(page-content/entry/content/hr) = 1"> <xsl:apply-templates select="page-content/entry/content" mode="before-hr" /> <xsl:apply-templates select="page-content/entry/content" mode="after-hr" /> </xsl:when> <xsl:otherwise> <xsl:copy-of select="page-content/entry/content/*" /> </xsl:otherwise> </choose> --> <!-- Fetch the content before the horizontal rule: --> <xsl:template match="*" mode="before-hr"> <xsl:copy-of select="./*[following-sibling::hr]" /> </xsl:template> <!-- Fetch the content after the horizontal rule: --> <xsl:template match="*" mode="after-hr"> <xsl:copy-of select="./*[preceding-sibling::hr]" /> </xsl:template> </xsl:stylesheet>