From: <hei...@us...> - 2009-10-13 00:10:06
|
Revision: 5352 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=5352&view=rev Author: heikkidoeleman Date: 2009-10-13 00:10:00 +0000 (Tue, 13 Oct 2009) Log Message: ----------- Clickable hyperlinks Modified Paths: -------------- branches/2.4.x/web/geonetwork/xsl/metadata.xsl branches/2.4.x/web/geonetwork/xsl/search-results-xhtml.xsl Added Paths: ----------- branches/2.4.x/web/geonetwork/xsl/text-utilities.xsl Modified: branches/2.4.x/web/geonetwork/xsl/metadata.xsl =================================================================== --- branches/2.4.x/web/geonetwork/xsl/metadata.xsl 2009-10-13 00:09:09 UTC (rev 5351) +++ branches/2.4.x/web/geonetwork/xsl/metadata.xsl 2009-10-13 00:10:00 UTC (rev 5352) @@ -6,7 +6,9 @@ xmlns:xlink="http://www.w3.org/1999/xlink" exclude-result-prefixes="exslt xlink gco geonet"> + <xsl:import href="text-utilities.xsl"/> <xsl:include href="metadata-utils.xsl"/> + <xsl:include href="metadata-controls.xsl"/> <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> @@ -660,7 +662,18 @@ </xsl:call-template> </xsl:if> </th> - <td class="padded" valign="top"><xsl:copy-of select="$text"/></td> + <td class="padded" valign="top"> + <xsl:choose> + <xsl:when test="$edit"> + <xsl:copy-of select="$text"/> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="addHyperlinksAndLineBreaks"> + <xsl:with-param name="txt" select="$text"/> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> + </td> </tr> </xsl:template> <!-- Modified: branches/2.4.x/web/geonetwork/xsl/search-results-xhtml.xsl =================================================================== --- branches/2.4.x/web/geonetwork/xsl/search-results-xhtml.xsl 2009-10-13 00:09:09 UTC (rev 5351) +++ branches/2.4.x/web/geonetwork/xsl/search-results-xhtml.xsl 2009-10-13 00:10:00 UTC (rev 5352) @@ -3,6 +3,8 @@ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:geonet="http://www.fao.org/geonetwork" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="geonet exslt"> <xsl:include href="utils.xsl"/> + <xsl:include href="text-utilities.xsl"/> + <xsl:include href="metadata.xsl"/> <xsl:variable name="pageRange" select="5"/> @@ -290,7 +292,9 @@ </xsl:otherwise> </xsl:choose> <!-- <input id="selId" name="{$metadata/geonet:info/id}" type="checkbox" /> --> - <xsl:value-of select="$metadata/title"/> + <xsl:call-template name="addHyperlinksAndLineBreaks"> + <xsl:with-param name="txt" select="$metadata/title"/> + </xsl:call-template> </h1> </td> @@ -338,10 +342,15 @@ <xsl:choose> <!-- show a maximum of $maxAbstract characters in the abstract --> <xsl:when test="string-length ($metadata/abstract) > $maxAbstract"> - <xsl:value-of select="substring ($metadata/abstract, 0, $maxAbstract)"/>... + <xsl:call-template name="addHyperlinksAndLineBreaks"> + <xsl:with-param name="txt" select="substring ($metadata/abstract, 0, $maxAbstract)"/> + </xsl:call-template> + ... </xsl:when> <xsl:otherwise> - <xsl:value-of select="$metadata/abstract"/> + <xsl:call-template name="addHyperlinksAndLineBreaks"> + <xsl:with-param name="txt" select="$metadata/abstract"/> + </xsl:call-template> </xsl:otherwise> </xsl:choose> </td> Added: branches/2.4.x/web/geonetwork/xsl/text-utilities.xsl =================================================================== --- branches/2.4.x/web/geonetwork/xsl/text-utilities.xsl (rev 0) +++ branches/2.4.x/web/geonetwork/xsl/text-utilities.xsl 2009-10-13 00:10:00 UTC (rev 5352) @@ -0,0 +1,206 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:fn="http://www.w3.org/2005/02/xpath-functions"> + +<!-- --> +<!-- Collection of utilities handy in text processing. --> +<!-- --> + + + <!-- --> + <!-- Just as substring-before, but matching the delimiter only if --> + <!-- it occurs after position. --> + <!-- --> + <xsl:template name="substring-before-from"> + <xsl:param name="start-position"/> + <xsl:param name="delimiter"/> + <xsl:param name="string"/> + + <xsl:variable name="string-before-position" select="substring($string, 1, $start-position - 1)"/> + <xsl:variable name="string-after-position" select="substring($string, $start-position)"/> + <xsl:variable name="first-word-after-position" select="substring-before($string-after-position, $delimiter)"/> + + <xsl:choose> + <xsl:when test="$first-word-after-position"> + <xsl:value-of select="concat($string-before-position, $first-word-after-position)"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$string"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + + <!-- --> + <!-- Template to add HTML hyperlinks if your text contains them; also breaks --> + <!-- long words that might otherwise run outside your containing <div>. --> + <!-- --> + <!-- Divide-and-conquer (DVC) version to avoid stack overflow for long texts --> + <!-- --> + <xsl:template name="addHyperlinksAndLineBreaks"> + <xsl:param name="txt"/> + <xsl:choose> + <xsl:when test="/root/gui/env/clickablehyperlinks/enable = 'true'"> + + <xsl:variable name="nTxt" select="normalize-space($txt)"/> + <xsl:variable name="first-word" select="substring-before($nTxt,' ')"/> + + <xsl:variable name="rest" select="substring-after($nTxt,' ')"/> + + <xsl:choose> + <!-- there is more than 1 word --> + <xsl:when test="$first-word"> + <!-- handle first word --> + <xsl:variable name="first-word-with-space-appended" select="concat($first-word,' ')"/> + + <xsl:call-template name="addHyperlinksAndLineBreaksToSingleWord"> + <xsl:with-param name="word" select="$first-word-with-space-appended"/> + </xsl:call-template> + + <!-- halve the rest, breaking at space --> + <xsl:variable name="half-length" select="floor(string-length($rest) div 2)"/> + + <xsl:variable name="first-half"> + <xsl:call-template name="substring-before-from"> + <xsl:with-param name="start-position" select="$half-length"/> + <xsl:with-param name="delimiter" select="' '"/> + <xsl:with-param name="string" select="$rest"/> + </xsl:call-template> + </xsl:variable> + + <xsl:variable name="second-half" select="substring($rest, string-length($first-half) + 1)"/> + + <!-- recursively handle the first half of the rest of the words --> + <xsl:call-template name="addHyperlinksAndLineBreaks"> + <xsl:with-param name="txt" select="$first-half"/> + </xsl:call-template> + + <!-- recursively handle the second half of the rest of the words --> + <xsl:call-template name="addHyperlinksAndLineBreaks"> + <xsl:with-param name="txt" select="$second-half"/> + </xsl:call-template> + + </xsl:when> + <!-- there is exactly 1 word --> + <xsl:when test="$txt"> + <!-- handle the word --> + <xsl:variable name="word-with-space-appended" select="concat($txt,' ')"/> + <xsl:call-template name="addHyperlinksAndLineBreaksToSingleWord"> + <xsl:with-param name="word" select="$word-with-space-appended"/> + </xsl:call-template> + </xsl:when> + </xsl:choose> + </xsl:when> + <xsl:otherwise> + ZZZ<xsl:value-of select="$txt"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + + <!-- --> + <!-- Adds a <br/> if word is longer than a max length. --> + <!-- --> + <xsl:template name="addLineBreaksToSingleWord"> + <xsl:param name="word"/> + <xsl:param name="maxWordLength"/> + <xsl:choose> + <!-- line break if word is longer than 56 characters --> + <xsl:when test="string-length($word) > $maxWordLength"> + <xsl:value-of select="substring($word, 0, $maxWordLength)"/> + <br/> + <xsl:call-template name="addLineBreaksToSingleWord"> + <xsl:with-param name="word" select="substring($word, $maxWordLength)"/> + <xsl:with-param name="maxWordLength" select="$maxWordLength"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$word"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + + <!-- --> + <!-- Adds hyperlinks to a word and adds <br/> if word is longer than max length. --> + <!-- --> + <xsl:template name="addHyperlinksAndLineBreaksToSingleWord"> + <xsl:param name="word"/> + <xsl:variable name="maxWordLength" select="56"/> + + <!-- if word contains ), remove remainder from processing here --> + <!-- this is to cope with texts containing "(http://blah.org)," --> + <!-- (the part from the ')' is not part of the hyperlink) --> + <xsl:variable name="word-to-use"> + <xsl:choose> + <xsl:when test="contains($word, ')')"> + <xsl:value-of select="substring-before($word, ')')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$word"/> + </xsl:otherwise> + </xsl:choose> + + </xsl:variable> + + <xsl:choose> + <!-- http links --> + <xsl:when test="substring($word-to-use, 0, 8) = 'http://'"> + <a style="font-weight:bolder;"> + <xsl:attribute name="href"> + <xsl:value-of select="$word-to-use"/> + </xsl:attribute> + <xsl:call-template name="addLineBreaksToSingleWord"> + <xsl:with-param name="word" select="$word-to-use"/> + <xsl:with-param name="maxWordLength" select="$maxWordLength"/> + </xsl:call-template> + </a> + </xsl:when> + <!-- https links --> + <xsl:when test="substring($word-to-use, 0, 9) = 'https://'"> + <a style="font-weight:bolder;"> + <xsl:attribute name="href"> + <xsl:value-of select="$word-to-use"/> + </xsl:attribute> + <xsl:call-template name="addLineBreaksToSingleWord"> + <xsl:with-param name="word" select="$word-to-use"/> + <xsl:with-param name="maxWordLength" select="$maxWordLength"/> + </xsl:call-template> + </a> + </xsl:when> + <!-- ftp links --> + <xsl:when test="substring($word-to-use, 0, 7) = 'ftp://'"> + <a style="font-weight:bolder;"> + <xsl:attribute name="href"> + <xsl:value-of select="$word-to-use"/> + </xsl:attribute> + <xsl:call-template name="addLineBreaksToSingleWord"> + <xsl:with-param name="word" select="$word-to-use"/> + <xsl:with-param name="maxWordLength" select="$maxWordLength"/> + </xsl:call-template> + </a> + </xsl:when> + <!-- mailto links --> + <xsl:when test="contains($word-to-use, '@')"> + <a style="font-weight:bolder;"> + <xsl:attribute name="href"> + mailto:<xsl:value-of select="$word-to-use"/> + </xsl:attribute> + <xsl:call-template name="addLineBreaksToSingleWord"> + <xsl:with-param name="word" select="$word-to-use"/> + <xsl:with-param name="maxWordLength" select="$maxWordLength"/> + </xsl:call-template> + </a> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="addLineBreaksToSingleWord"> + <xsl:with-param name="word" select="$word-to-use"/> + <xsl:with-param name="maxWordLength" select="$maxWordLength"/> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> + + <xsl:if test="contains($word, ')')"> + <xsl:text>)</xsl:text><xsl:value-of select="substring-after($word, ')')"/> + </xsl:if> + + </xsl:template> + +</xsl:stylesheet> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |