<?xml version='1.0'?>

<!--

	style-searchRetrieve.xsl - transform an SRU search result into HTML

	Eric Lease Morgan <emorgan@nd.edu>
	(c) University of Notre Dame; distributed under a GNU Public License

	August   11, 2023 - first documentation
	September 5, 2023 - calling it version 1.0; while in Bologna

-->


<xsl:stylesheet
	xmlns:zs="http://docs.oasis-open.org/ns/search-ws/sruResponse"
	xmlns:slim="http://www.loc.gov/MARC21/slim"
	xmlns:fr="http://docs.oasis-open.org/ns/search-ws/facetedResults"
	xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>

  <xsl:template match='/'>
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
      <head>
        <title>Distant Reader catalog index result</title>
		<style>
			body {margin: 7%;}
			ul {margin-bottom: 1em;}
		</style>
      </head>
      <body>
      
        <h1>Distant Reader index search result</h1>
        
		<div>
		<p>Your search matched <xsl:value-of select='zs:searchRetrieveResponse/zs:numberOfRecords' /> record(s), and as many as <xsl:value-of select="/zs:searchRetrieveResponse/zs:echoedSearchRetrieveRequest/zs:maximumRecords" /> are listed below. Use the results to refine your search, or submit additional parameters.</p>

		<form method='GET' action='http://index.distantreader.org/biblios'>
			<input type='hidden' name='version'        value='2.0' />
			<input type='hidden' name='operation'      value='searchRetrieve' />
			<input type='hidden' name='maximumRecords' value='512' />
			<input type='hidden' name='recordSchema'   value='marcxml' />
			<input type='hidden' name='facetLimit'     value='32' />
			<input type='hidden' name='stylesheet'     value='style-searchRetrieve.xsl' />
			<input>
				<xsl:attribute name="type">text</xsl:attribute>
				<xsl:attribute name="size">96</xsl:attribute>
				<xsl:attribute name="name">query</xsl:attribute>
				<xsl:attribute name="value"><xsl:value-of select='zs:searchRetrieveResponse/zs:echoedSearchRetrieveRequest/zs:query' /></xsl:attribute>
				</input>
				<xsl:text> </xsl:text>
			<input type='submit' value='Search' />
		</form>
		
		<p>The <xsl:value-of select='zs:searchRetrieveResponse/zs:numberOfRecords' /> results look good and/or interesting? <a><xsl:attribute name='href'>https://distantreader.org/patrons/buildFromQuery?query=<xsl:value-of select='zs:searchRetrieveResponse/zs:echoedSearchRetrieveRequest/zs:query' /></xsl:attribute>Automatically build a data set</a> from the results. These data sets are affectionately called "study carrels", and you can use them to quickly and easily read dozens of books or hundreds of articles.</p>
		</div>
		
		<div>
			<h2>Facets</h2>

			<!-- initialize -->
			<xsl:variable name="query">
				<xsl:text>(</xsl:text>
				<xsl:value-of select="zs:searchRetrieveResponse/zs:echoedSearchRetrieveRequest/zs:query" />
				<xsl:text>)</xsl:text>
			</xsl:variable>

			<xsl:for-each select='//fr:facet'>
				<p>
					<xsl:variable name="index" select="./fr:index" />

					<!-- translate index name -->
					<xsl:choose>
						<xsl:when test="$index='au'">
							<b><xsl:text>Authors</xsl:text></b><xsl:text>: </xsl:text>
						</xsl:when>
						<xsl:when test="$index='ccode'">
							<b><xsl:text>Collections</xsl:text></b><xsl:text>: </xsl:text>
						</xsl:when>
						<xsl:when test="$index='itype'">
							<b><xsl:text>Item types</xsl:text></b><xsl:text>: </xsl:text>
						</xsl:when>
						<xsl:when test="$index='su-to'">
							<b><xsl:text>Subjects</xsl:text></b><xsl:text>: </xsl:text>
						</xsl:when>
					</xsl:choose>

					<xsl:for-each select='./fr:terms/fr:term'>

						<xsl:choose>
							<xsl:when test="$index='au'">
								<a>
									<xsl:attribute name="href">http://index.distantreader.org/biblios?version=2.0&amp;facetLimit=32&amp;operation=searchRetrieve&amp;maximumRecords=512&amp;stylesheet=style-searchRetrieve.xsl&amp;recordSchema=marcxml&amp;query=<xsl:value-of select='$query'/><xsl:text> and dc.author="</xsl:text><xsl:value-of select="./fr:actualTerm" />"</xsl:attribute>
									<xsl:value-of select="./fr:actualTerm" />
								</a>
							</xsl:when>
							<xsl:when test="$index='ccode'">
								<a>
									<xsl:attribute name="href">http://index.distantreader.org/biblios?version=2.0&amp;facetLimit=32&amp;operation=searchRetrieve&amp;maximumRecords=512&amp;stylesheet=style-searchRetrieve.xsl&amp;recordSchema=marcxml&amp;query=<xsl:value-of select='$query'/><xsl:text> and koha.ccode="</xsl:text><xsl:value-of select="./fr:actualTerm" />"</xsl:attribute>
									<xsl:value-of select="./fr:actualTerm" />
								</a>
							</xsl:when>
							<xsl:when test="$index='itype'">
								<a>
									<xsl:attribute name="href">http://index.distantreader.org/biblios?version=2.0&amp;facetLimit=32&amp;operation=searchRetrieve&amp;maximumRecords=512&amp;stylesheet=style-searchRetrieve.xsl&amp;recordSchema=marcxml&amp;query=<xsl:value-of select='$query'/><xsl:text> and koha.itemtype="</xsl:text><xsl:value-of select="./fr:actualTerm" />"</xsl:attribute>
									<xsl:value-of select="./fr:actualTerm" />
								</a>
							</xsl:when>
							<xsl:when test="$index='su-to'">
								<a>
									<xsl:attribute name="href">http://index.distantreader.org/biblios?version=2.0&amp;facetLimit=32&amp;operation=searchRetrieve&amp;maximumRecords=512&amp;stylesheet=style-searchRetrieve.xsl&amp;recordSchema=marcxml&amp;query=<xsl:value-of select='$query'/><xsl:text> and dc.subject="</xsl:text><xsl:value-of select="./fr:actualTerm" />"</xsl:attribute>
									<xsl:value-of select="./fr:actualTerm" />
								</a>
							</xsl:when>
						</xsl:choose>

						<xsl:text> (</xsl:text>
						<xsl:value-of select='./fr:count' />
						<xsl:text>); </xsl:text>

					</xsl:for-each>
				</p>
			</xsl:for-each>
		</div>
		
		<div>
		<h2>Results</h2>
		 <ol>
			<xsl:for-each select='//zs:recordData/slim:record'>
				<li><xsl:value-of select="slim:datafield[@tag=245]/slim:subfield" /></li>
				<ul>
					<li><b>authors/contributors: </b>
						<xsl:for-each select='slim:datafield[@tag=100]|slim:datafield[@tag=700]'>
							<a>
								<xsl:attribute name="href">http://index.distantreader.org/biblios?version=2.0&amp;facetLimit=32&amp;operation=searchRetrieve&amp;maximumRecords=512&amp;stylesheet=style-searchRetrieve.xsl&amp;recordSchema=marcxml&amp;query=dc.author="<xsl:value-of select='slim:subfield' />"</xsl:attribute>
							<xsl:value-of select='slim:subfield' /><xsl:text>; </xsl:text>
							</a>
						</xsl:for-each>
					</li>
					<li>
						<b>publisher/journal: </b>
						<xsl:value-of select="slim:datafield[@tag=260]/slim:subfield" />
					</li>
					<li>
						<b>collection: </b>
						<a>
							<xsl:attribute name="href">http://index.distantreader.org/biblios?version=2.0&amp;facetLimit=32&amp;operation=searchRetrieve&amp;maximumRecords=512&amp;stylesheet=style-searchRetrieve.xsl&amp;recordSchema=marcxml&amp;query=koha.ccode=<xsl:value-of select="slim:datafield[@tag=952]/slim:subfield[@code=8]" /></xsl:attribute>
							<xsl:value-of select="slim:datafield[@tag=952]/slim:subfield[@code=8]" />
						</a>
					</li>
					<li>
						<b>type: </b>
						<a>
							<xsl:attribute name="href">http://index.distantreader.org/biblios?version=2.0&amp;facetLimit=32&amp;operation=searchRetrieve&amp;maximumRecords=512&amp;stylesheet=style-searchRetrieve.xsl&amp;recordSchema=marcxml&amp;query=koha.itemtype=<xsl:value-of select="slim:datafield[@tag=952]/slim:subfield[@code='y']" /></xsl:attribute>
							<xsl:value-of select="slim:datafield[@tag=952]/slim:subfield[@code='y']" />
						</a>
					</li>
					<li>
						<b>abstract: </b>
						<xsl:value-of select="slim:datafield[@tag=520]/slim:subfield" />
					</li>
					<li><b>keywords/subjects: </b>
						<xsl:for-each select='slim:datafield[@tag=650]'>
							<a>
								<xsl:attribute name="href">http://index.distantreader.org/biblios?version=2.0&amp;facetLimit=32&amp;operation=searchRetrieve&amp;maximumRecords=512&amp;stylesheet=style-searchRetrieve.xsl&amp;recordSchema=marcxml&amp;query=dc.subject="<xsl:value-of select='slim:subfield' />"</xsl:attribute>
								<xsl:value-of select='slim:subfield' />
							</a>
							<xsl:text>; </xsl:text>
						</xsl:for-each>
					</li>
					<li>
						<b>DOI: </b>
						<xsl:value-of select="slim:datafield[@tag=024]/slim:subfield" />
					</li>					
					<li><b>links to: </b>
						<xsl:for-each select='slim:datafield[@tag=856]'>
							<a>
								<xsl:attribute name="href"><xsl:value-of select='slim:subfield[1]' /></xsl:attribute>
								<xsl:value-of select='slim:subfield[2]' />
							</a>
							<xsl:text>; </xsl:text>
						</xsl:for-each>
					</li>
				</ul>
			</xsl:for-each>
        </ol>
        </div>
        <hr />
        <p style='text-align:right'>Eric Lease Morgan &lt;emorgan@nd.edu&gt;</p>
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>
