For the Research Commons badges, we modified dspace-xmlui-mirage2/src/main/webapp/xsl/preprocess.xsl
and intercepted the rendering of the corresponding elements, ie
<!-- render frequency counts in sidebar facets as badges -->
<xsl:template match="dri:list[@id='aspect.discovery.Navigation.list.discovery']/dri:list/dri:item/dri:xref">
<xref>
<xsl:call-template name="copy-attributes"/>
<xsl:choose>
<xsl:when test="contains(text(), ' (') and contains(substring-after(text(), ' ('), ')')">
<xsl:variable name="title">
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string" select="text()"/>
<xsl:with-param name="separator"><xsl:text> (</xsl:text></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="count">
<xsl:call-template name="remove-parens">
<xsl:with-param name="string" select="normalize-space(substring-after(text(), $title))"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$title"/>
<xsl:text> </xsl:text>
<hi rend="badge">
<xsl:value-of select="$count"/>
</hi>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xref>
</xsl:template>
And a similar template for the currently selected facet value (that IIRC isn't a link):
<!-- better highlight active co-author/subject etc in facet list, incl show count as badge -->
<xsl:template match="dri:list[@id='aspect.discovery.Navigation.list.discovery']/dri:list/dri:item[@rend='selected']">
<item>
<xsl:call-template name="copy-attributes"/>
<xsl:attribute name="rend"><xsl:value-of select="@rend"/> disabled</xsl:attribute>
<xsl:choose>
<xsl:when test="contains(text(), ' (') and contains(substring-after(text(), ' ('), ')')">
<xsl:variable name="title">
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string" select="text()"/>
<xsl:with-param name="separator"><xsl:text> (</xsl:text></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="count">
<xsl:call-template name="remove-parens">
<xsl:with-param name="string" select="normalize-space(substring-after(text(), $title))"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$title"/>
<xsl:text> </xsl:text>
<hi rend="badge">
<xsl:value-of select="$count"/>
</hi>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</item>
</xsl:template>
You'll see that there is a bit of XSL/T trickery involved to cope with cases where the facet value itself contains parentheses, with a couple of utility templates:
<xsl:template name="substring-before-last">
<xsl:param name="string" select="''" />
<xsl:param name="separator" select="''" />
<xsl:if test="$string != '' and $separator != ''">
<xsl:variable name="head" select="substring-before($string, $separator)" />
<xsl:variable name="tail" select="substring-after($string, $separator)" />
<xsl:value-of select="$head" />
<xsl:if test="contains($tail, $separator)">
<xsl:value-of select="$separator" />
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string" select="$tail" />
<xsl:with-param name="separator" select="$separator" />
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template name="remove-parens">
<xsl:param name="string" select="''" />
<xsl:if test="starts-with($string, '(') and substring($string, string-length($string))=')'">
<xsl:value-of select="substring($string, 2, string-length($string) - 2)"/>
</xsl:if>
</xsl:template>
Just a note to add that we have a local preference for modifying the theme XSL files over modifying the Java code. You could do this in the Java code as an alternative, but you'd need to work within the DRI API, eg make .addHighlight("badge")
Java method calls together with the addXref
(DRI hi
gets transformed to HTML span
). See DRI documentation at https://wiki.duraspace.org/display/DSDOC5x/DRI+Schema+Reference (for 5.x but unchanged for 6.x).
The Cocoon pipeline is Java produces DRI (XML) -> preprocess.xsl and related files modify the DRI and output is still DRI -> theme.xsl and related files transform the DRI into HTML. You're trying to create HTML "too early" in the pipeline. Your raw HTML is escaped further down the track, which is why you're seeing the tags on screen.