Skip to content

Instantly share code, notes, and snippets.

@aschweer
Created November 1, 2012 22:31
Show Gist options
  • Save aschweer/3997137 to your computer and use it in GitHub Desktop.
Save aschweer/3997137 to your computer and use it in GitHub Desktop.
DSpace XMLUI render newlines in abstract metadata
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xsl xhtml">
<!-- make sure double linefeeds are rendered as paragraph breaks -->
<xsl:template name="break">
<xsl:param name="text" select="."/>
<xsl:choose>
<xsl:when test="contains($text, '&#xa;&#xd;&#xa;')">
<p>
<xsl:call-template name="breaklines">
<xsl:with-param name="text" select="substring-before($text, '&#xa;&#xd;&#xa;')"/>
</xsl:call-template>
</p>
<xsl:call-template name="break">
<xsl:with-param name="text" select="substring-after($text, '&#xa;&#xd;&#xa;')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:call-template name="breaklines">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- make sure single linefeeds are rendered as line breaks -->
<xsl:template name="breaklines">
<xsl:param name="text" select="."/>
<xsl:choose>
<xsl:when test="contains($text, '&#xa;')">
<xsl:value-of select="substring-before($text, '&#xa;')"/>
<br/>
<xsl:call-template name="breaklines">
<xsl:with-param name="text" select="substring-after($text, '&#xa;')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
@aschweer
Copy link
Author

aschweer commented Nov 1, 2012

Include this from your theme's main XSL file. Then in item-view.xsl, make sure to call

<xsl:call-template name="break">
    <xsl:with-param name="text" select="./node()"/>
</xsl:call-template>

rather than just

<xsl:value-of select="node()"/>

when outputting the value of the metadata field (for those metadata fields where you want to show linebreaks, eg dc.description.abstract)

@vnguyenanh
Copy link

Dear Andrea,
Could you please tell me where the location copy file "linebreaks.xsl"?
And now, I have two files "item-view.xsl". which file do I have to edit after adding the file "linebreaks.xsl"?

  • D:\dspace\webapps\xmlui\themes\dri2xhtml-alt\aspect\artifactbrowser
  • D:\dspace\webapps\xmlui\themes\Mirage\lib\xsl\aspect\artifactbrowser

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment