Skip to content

Commit

Permalink
MIR-1241 Moved facet related template to response-facets.xsl. Use inc…
Browse files Browse the repository at this point in the history
…lude via resource: uri
  • Loading branch information
Possommi committed Nov 17, 2023
1 parent 6521cda commit 8d2686d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 154 deletions.
94 changes: 42 additions & 52 deletions mir-module/src/main/resources/xsl/response-facets.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<xsl:value-of select="concat('notnull:classification:metadata:all:children:',$facet_name)"/>
</xsl:variable>

<!-- TODO: remove conditions for facets 'worldReadableComplete' and 'mods.genre' after code refactoring -->
<xsl:if test="self::node()[@name=$facet_name]/int">
<div class="card {$facet_name}">
<div class="card-header" data-toggle="collapse-next">
Expand Down Expand Up @@ -111,104 +110,95 @@
</xsl:template>

<xsl:template match="/response/lst[@name='facet_counts']/lst[@name='facet_fields']">
<xsl:param name="facet_name"/>
<xsl:param name="classId"/>
<xsl:param name="i18nPrefix"/>
<xsl:param name="classification"/>

<xsl:param name="facet_name" />
<xsl:param name="classId" />
<xsl:param name="categoryClassValues" select="false()"/>
<xsl:param name="i18nPrefix" />
<xsl:for-each select="lst[@name=$facet_name]/int">
<xsl:variable name="fqValue" select="concat($facet_name,':',@name)"/>
<xsl:variable name="fqFragment" select="concat('fq=',$fqValue)"/>
<xsl:variable name="fqFragmentEncoded" select="concat('fq=',encoder:encode($fqValue, 'UTF-8'))"/>
<xsl:variable name="queryWithoutStart"
select="mcrxsl:regexp($RequestURL, '(&amp;|%26)(start=)[0-9]*', '')"/>
<xsl:variable name="fqValue" >
<xsl:choose>
<xsl:when test="$categoryClassValues">
<xsl:value-of select="concat($classId,':',substring-before(@name,':'),'%5C:',substring-after(@name,':'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($classId,':',@name)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="fqResponseValue" >
<xsl:choose>
<xsl:when test="$categoryClassValues">
<xsl:value-of select="concat($classId,':',substring-before(@name,':'),'\:',substring-after(@name,':'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($classId,':',@name)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="fqFragment" select="concat('fq=',$fqValue)" />
<xsl:variable name="fqFragmentEncoded" select="concat('fq=',encoder:encode($fqResponseValue, 'UTF-8'))" />
<xsl:variable name="queryWithoutStart" select="mcrxsl:regexp($RequestURL, '(&amp;|%26)(start=)[0-9]*', '')" />
<xsl:variable name="queryURL">
<xsl:choose>
<xsl:when test="contains($queryWithoutStart, $fqFragment)">
<xsl:choose>
<xsl:when test="not(substring-after($queryWithoutStart, $fqFragment))">
<!-- last parameter -->
<xsl:value-of
select="substring($queryWithoutStart, 1, string-length($queryWithoutStart) - string-length($fqFragment) - 1)"/>
<xsl:value-of select="substring($queryWithoutStart, 1, string-length($queryWithoutStart) - string-length($fqFragment) - 1)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="concat(substring-before($queryWithoutStart, $fqFragment), substring-after($queryWithoutStart, concat($fqFragment,'&amp;')))"/>
<xsl:value-of select="concat(substring-before($queryWithoutStart, $fqFragment), substring-after($queryWithoutStart, concat($fqFragment,'&amp;')))" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="contains($queryWithoutStart, $fqFragmentEncoded)">
<xsl:choose>
<xsl:when test="not(substring-after($queryWithoutStart, $fqFragmentEncoded))">
<!-- last parameter -->
<xsl:value-of
select="substring($queryWithoutStart, 1, string-length($queryWithoutStart) - string-length($fqFragmentEncoded) - 1)"/>
<xsl:value-of select="substring($queryWithoutStart, 1, string-length($queryWithoutStart) - string-length($fqFragmentEncoded) - 1)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="concat(substring-before($queryWithoutStart, $fqFragmentEncoded), substring-after($queryWithoutStart, concat($fqFragmentEncoded,'&amp;')))"/>
<xsl:value-of select="concat(substring-before($queryWithoutStart, $fqFragmentEncoded), substring-after($queryWithoutStart, concat($fqFragmentEncoded,'&amp;')))" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="not(contains($queryWithoutStart, '?'))">
<xsl:value-of select="concat($queryWithoutStart, '?', $fqFragment)"/>
<xsl:value-of select="concat($queryWithoutStart, '?', $fqFragment)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($queryWithoutStart, '&amp;', $fqFragment)"/>
<xsl:value-of select="concat($queryWithoutStart, '&amp;', $fqFragment)" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<li data-fq="{$fqValue}">
<li data-fq="{$fqResponseValue}">
<div class="custom-control custom-checkbox" onclick="location.href='{$queryURL}';">
<input type="checkbox" class="custom-control-input">
<xsl:if test="
/response/lst[@name='responseHeader']/lst[@name='params']/str[@name='fq' and text() = $fqValue] |
/response/lst[@name='responseHeader']/lst[@name='params']/arr[@name='fq']/str[text() = $fqValue]">
/response/lst[@name='responseHeader']/lst[@name='params']/str[@name='fq' and text() = $fqResponseValue] |
/response/lst[@name='responseHeader']/lst[@name='params']/arr[@name='fq']/str[text() = $fqResponseValue]">
<xsl:attribute name="checked">true</xsl:attribute>
</xsl:if>
</input>
<label class="custom-control-label">
<span class="title">
<xsl:choose>

<xsl:when test="name(document($classification)/*) != 'null'">
<xsl:variable name="category" select="@name"/>
<xsl:variable name="category_label" select="document($classification)/mycoreclass/categories/category[@ID=$category]/label[@xml:lang=$CurrentLang]/@text"/>
<xsl:choose>
<xsl:when test="$category_label != ''">
<xsl:value-of select="$category_label"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
<xsl:when test="$categoryClassValues">
<xsl:value-of select="mcrxsl:getDisplayName(substring-before(@name,':'),substring-after(@name,':'))" />
</xsl:when>

<xsl:when test="string-length($classId) &gt; 0">
<xsl:variable name="displayName" select="mcrxsl:getDisplayName($classId, @name)"/>
<xsl:choose>
<xsl:when test="displayName">
<xsl:value-of select="$displayName"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="mcrxsl:getDisplayName($classId, @name)" />
</xsl:when>
<xsl:when test="string-length($i18nPrefix) &gt; 0">
<xsl:value-of select="i18n:translate(concat($i18nPrefix,@name))"
disable-output-escaping="yes"/>
<xsl:value-of select="i18n:translate(concat($i18nPrefix,@name))" disable-output-escaping="yes" />
</xsl:when>

<xsl:otherwise>
<xsl:value-of select="@name"/>
<xsl:value-of select="@name" />
</xsl:otherwise>

</xsl:choose>
</span>
<span class="hits">
<xsl:value-of select="."/>
<xsl:value-of select="." />
</span>
</label>
</div>
Expand Down
105 changes: 3 additions & 102 deletions mir-module/src/main/resources/xsl/response-mir.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
xmlns:mcrxsl="xalan://org.mycore.common.xml.MCRXMLFunctions"
xmlns:basket="xalan://org.mycore.frontend.basket.MCRBasketManager"
xmlns:decoder="xalan://java.net.URLDecoder"
exclude-result-prefixes="i18n mods str exslt mcr acl mcrxsl basket encoder decoder"
>
exclude-result-prefixes="i18n mods str exslt mcr acl mcrxsl basket encoder decoder">

<xsl:include href="response-mir-utils.xsl" />
<xsl:include href="csl-export-gui.xsl" />
<xsl:include href="resource:xsl/csl-export-gui.xsl" />
<xsl:include href="resource:xsl/response-facets.xsl"/>

<xsl:include href="resource:xsl/response-mir-utils.xsl" />

<xsl:param name="UserAgent" />
<xsl:param name="MIR.testEnvironment" />
Expand Down Expand Up @@ -887,103 +885,6 @@
</xsl:choose>
</xsl:template>

<xsl:template match="/response/lst[@name='facet_counts']/lst[@name='facet_fields']">
<xsl:param name="facet_name" />
<xsl:param name="classId" />
<xsl:param name="categoryClassValues" select="false()"/>
<xsl:param name="i18nPrefix" />
<xsl:for-each select="lst[@name=$facet_name]/int">
<xsl:variable name="fqValue" >
<xsl:choose>
<xsl:when test="$categoryClassValues">
<xsl:value-of select="concat($classId,':',substring-before(@name,':'),'%5C:',substring-after(@name,':'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($classId,':',@name)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="fqResponseValue" >
<xsl:choose>
<xsl:when test="$categoryClassValues">
<xsl:value-of select="concat($classId,':',substring-before(@name,':'),'\:',substring-after(@name,':'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($classId,':',@name)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="fqFragment" select="concat('fq=',$fqValue)" />
<xsl:variable name="fqFragmentEncoded" select="concat('fq=',encoder:encode($fqResponseValue, 'UTF-8'))" />
<xsl:variable name="queryWithoutStart" select="mcrxsl:regexp($RequestURL, '(&amp;|%26)(start=)[0-9]*', '')" />
<xsl:variable name="queryURL">
<xsl:choose>
<xsl:when test="contains($queryWithoutStart, $fqFragment)">
<xsl:choose>
<xsl:when test="not(substring-after($queryWithoutStart, $fqFragment))">
<!-- last parameter -->
<xsl:value-of select="substring($queryWithoutStart, 1, string-length($queryWithoutStart) - string-length($fqFragment) - 1)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(substring-before($queryWithoutStart, $fqFragment), substring-after($queryWithoutStart, concat($fqFragment,'&amp;')))" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="contains($queryWithoutStart, $fqFragmentEncoded)">
<xsl:choose>
<xsl:when test="not(substring-after($queryWithoutStart, $fqFragmentEncoded))">
<!-- last parameter -->
<xsl:value-of select="substring($queryWithoutStart, 1, string-length($queryWithoutStart) - string-length($fqFragmentEncoded) - 1)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(substring-before($queryWithoutStart, $fqFragmentEncoded), substring-after($queryWithoutStart, concat($fqFragmentEncoded,'&amp;')))" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="not(contains($queryWithoutStart, '?'))">
<xsl:value-of select="concat($queryWithoutStart, '?', $fqFragment)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($queryWithoutStart, '&amp;', $fqFragment)" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<li data-fq="{$fqResponseValue}">
<div class="custom-control custom-checkbox" onclick="location.href='{$queryURL}';">
<input type="checkbox" class="custom-control-input">
<xsl:if test="
/response/lst[@name='responseHeader']/lst[@name='params']/str[@name='fq' and text() = $fqResponseValue] |
/response/lst[@name='responseHeader']/lst[@name='params']/arr[@name='fq']/str[text() = $fqResponseValue]">
<xsl:attribute name="checked">true</xsl:attribute>
</xsl:if>
</input>
<label class="custom-control-label">
<span class="title">
<xsl:choose>
<xsl:when test="$categoryClassValues">
<xsl:value-of select="mcrxsl:getDisplayName(substring-before(@name,':'),substring-after(@name,':'))" />
</xsl:when>
<xsl:when test="string-length($classId) &gt; 0">
<xsl:value-of select="mcrxsl:getDisplayName($classId, @name)" />
</xsl:when>
<xsl:when test="string-length($i18nPrefix) &gt; 0">
<xsl:value-of select="i18n:translate(concat($i18nPrefix,@name))" disable-output-escaping="yes" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name" />
</xsl:otherwise>
</xsl:choose>
</span>
<span class="hits">
<xsl:value-of select="." />
</span>
</label>
</div>
</li>
</xsl:for-each>
</xsl:template>

<xsl:template name="print.classiFilter">
<xsl:param name="classId" />
<xsl:param name="i18nKey" />
Expand Down

0 comments on commit 8d2686d

Please sign in to comment.