对于 Research Commons 徽章,我们修改了dspace-xmlui-mirage2/src/main/webapp/xsl/preprocess.xsl,并截取了对应元素的渲染,即
<!-- 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>
还有一个用于当前选择的构面值的类似模板(IIRC 不是链接):
<!-- 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>
您会看到,涉及到一些 XSL/T 技巧来处理构面值本身包含括号的情况,并带有几个实用程序模板:
<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>
只是要补充一点,我们在本地偏好修改主题 XSL 文件而不是修改 Java 代码。作为替代方案,您可以在 Java 代码中执行此操作,但您需要在 DRI API 中工作,例如,将 .addHighlight("badge") Java 方法调用与 addXref 一起调用(DRI hi 转换为 HTML span )。请参阅https://wiki.duraspace.org/display/DSDOC5x/DRI+Schema+Reference 上的 DRI 文档(对于 5.x,但对于 6.x 保持不变)。
Cocoon 管道是 Java 生成 DRI (XML) -> preprocess.xsl 和相关文件修改 DRI 并且输出仍然是 DRI -> theme.xsl 和相关文件将 DRI 转换为 HTML。您正在尝试在管道中“过早”创建 HTML。您的原始 HTML 被进一步转义,这就是您在屏幕上看到标签的原因。