Skip to content

Instantly share code, notes, and snippets.

@craigtommola
Created August 20, 2019 21:03
Show Gist options
  • Save craigtommola/2af935355a903b938520cec06b17bb4d to your computer and use it in GitHub Desktop.
Save craigtommola/2af935355a903b938520cec06b17bb4d to your computer and use it in GitHub Desktop.
Accordions with Subheading and Pre-Expansion with Named Anchor
$(function() {
if(window.location.hash) {
var target = $(window.location.hash);
var accordion = $(target).parent().prev("dt");
$(accordion).addClass("expanded");
$(accordion).next("dd").slideDown();
$('html, body').animate({scrollTop: target.offset().top - 200},
500);
}
});
dl.definitions dt dfn span.vertical {
display: block;
}
<!-- S2. DL Accordion List -->
<xsl:template match="table[@class='ou_accordion']" >
<dl class="definitions">
<!-- for each content row -->
<xsl:for-each select="tbody/tr[position() mod 2 =0]">
<dt class="accordion-term">
<dfn>
<!-- This line watches for a "pseudo-tag" using underscores: _subhead_ ... _/subhead_ and converts to styled span tags -->
<xsl:value-of select="replace(replace(preceding-sibling::tr[1]/element(), '_subhead_','&lt;span class=&quot;vertical&quot;&gt;'), '_/subhead_', '&lt;/span&gt;')" disable-output-escaping="yes"/>
</dfn>
</dt>
<dd class="accordion-desc">
<a>
<xsl:attribute name="id">
<xsl:value-of select="lower-case(translate(normalize-space(string-join(replace(translate(substring-before(preceding-sibling::tr[1]/element(),'_subhead_'), '’', ''),'[^a-zA-Z0-9]', ' '))), ' ,', '-'))"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="replace(substring-before(preceding-sibling::tr[1]/element(),'_subhead_'), '&nbsp;',' ')"/>
</xsl:attribute>
</a>
<!-- current row copy tr or td -->
<xsl:apply-templates select="element()/node()"/>
</dd>
</xsl:for-each>
</dl><!-- /.definitions -->
</xsl:template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment