User Tools

Site Tools


en:user:gs3_sample_format_statements

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
en:user:gs3_sample_format_statements [2016/09/26 22:58] – [Linking metadata to a search] kjdonen:user:gs3_sample_format_statements [2016/10/09 22:40] – [adding in new javascript] kjdon
Line 183: Line 183:
 <code> <code>
 Search for Authors: <gsf:foreach-metadata name='dc.Creator'>  Search for Authors: <gsf:foreach-metadata name='dc.Creator'> 
-   <a><xsl:attribute name="href"><xsl:value-of select="$_httpquery_"/>/TextQuery?qs=1&amp;rt=rd&amp;s1.level=Doc&amp;startPage=1&amp;s1.query=<gsf:meta-value/>&amp;s1.index=CR</xsl:attribute><gsf:meta-value/></a><xsl:text>, </xsl:text>+   <a><xsl:attribute name="href"><xsl:value-of select="$_httpquery_"/>/TextQuery?qs=1&amp;rt=rd& 
 +   amp;s1.level=Doc&amp;startPage=1&amp;s1.query=<gsf:meta-value/>&amp;s1.index=CR</xsl:attribute> 
 +   <gsf:meta-value/></a><xsl:text>, </xsl:text>
 </gsf:foreach-metadata> </gsf:foreach-metadata>
 </code> </code>
Line 189: Line 191:
 <gsf:foreach-metadata> iterates over the list of values for the specified metadata, and <gsf:meta-value> outputs the current value each time. <gsf:foreach-metadata> iterates over the list of values for the specified metadata, and <gsf:meta-value> outputs the current value each time.
  
 +Use double quotes around the query value if you want exact matching, i.e.
 +<code>
 +s1.query="<gsf:meta-value/>"
 +</code>
 The parameters are: The parameters are:
   * qs=1  - this search is a quick search. Can omit if you want to be taken to the TextQuery search page (equivalent to clicking the TextQuery link under the quick search form)   * qs=1  - this search is a quick search. Can omit if you want to be taken to the TextQuery search page (equivalent to clicking the TextQuery link under the quick search form)
Line 197: Line 203:
   * s1.index=CR   - the index to search in, in this case the CR dc.Creator index.   * s1.index=CR   - the index to search in, in this case the CR dc.Creator index.
  
 +===== Using javascript to change the display =====
 +
 +As an example of using javascript, we will see how to output the document filesize in a human readable form. For example, instead of displaying "834716 bytes", it will display "815 KB".
 +
 +A basic javascript method to do this is the following:
 +
 +<code>
 +function humanReadableFileSize(bytes)
 +{
 +    var filesize = bytes + " bytes";
 +    if (bytes > 1048576) {
 + filesize = Math.round(bytes / 1048576.0) + " MB";
 +    }
 +    else if (bytes > 1024) {
 + filesize = Math.round(bytes/1024.0)+ " KB";
 +    }
 +    return filesize;
 +}
 +</code>
 +
 +So, we have a javascript function, but how do we get it into the page? 
 +Displaying human readable filesize.
 +
 + <gsf:template match="documentNode">
 +   <td>
 +     <gsf:link type="document">
 +       <gsf:metadata name="dls.Keyword"/>
 +     </gsf:link>
 +   </td>
 +   <td>
 +
 +     <script type="text/javascript">
 +    <xsl:text disable-output-escaping="yes">
 + bytes =</xsl:text><gsf:metadata name="FileSize"/><xsl:text  disable-output-escaping="yes">;
 +    var filesize = bytes + " bytes";
 + if (bytes > 1048576) {
 + filesize = Math.round(bytes / 1048576.0) + " MB";
 + }
 + else if (bytes > 1024) {
 + filesize = Math.round(bytes/1024.0)+ " KB";
 + }
 + document.write(filesize);
 +
 + </xsl:text>
 +    </script>
 +  </td>
 + </gsf:template>
  
  
en/user/gs3_sample_format_statements.txt · Last modified: 2023/03/13 01:46 by 127.0.0.1