I want to do a sipmle 'Muenchian grouping' in xslt 1.0 but also with an added wildcard search from a different node.
I'm familar with the grouping method and it's awlays worked well but am having trouble with the wildcard issue in that it always shows the group headings that do not have the wildcard search.
Here is my xml:
<objects>
<object>
<output_title>This is a title</output_title>
<output_year>2011</output_year>
</object>
<object>
<output_title>This is my title</output_title>
<output_year>2012</output_year>
</object>
<object>
<output_title>This is also my title</output_title>
<output_year>2012</output_year>
</object>
<object>
<output_title>This is another my title</output_title>
<output_year>2012</output_year>
</object>
<object>
<output_title>This is my title</output_title>
<output_year>2014</output_year>
</object>
<object>
<output_title>This is our title</output_title>
<output_year>2015</output_year>
</object>
</objects>
I want to output the following given a wildcard seach of the string 'my':
<h4>2012</h4>
<ol>
<li>This is my title</li>
<li>This is also my title</li>
<li>This is another my title</li>
</ol>
<h4>2014</h4>
<ol>
<li>This is my title</li>
</ol>
So the headings '2011' and '2015' should not appear (but they do and that is the problem)
Here is my XSLT 1.0:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="1.0">
<xsl:param name="search"/>
<!--Key for unique years-->
<xsl:key name="uniqueOutputYearHeading"
match="contains(translate(objects/object/output_title,$uppercase,$lowercase),translate($search,$uppercase,$lowercase))"
use="output_year"/>
<xsl:template match="/">
<!-- Generate the unique year headings-->
<xsl:for-each select="//object[generate-id(.)=generate-id(key('uniqueOutputYearHeading',output_year))]">
<xsl:sort select="output_year" data-type="number" order="descending"/>
<h4>
<xsl:value-of select="output_year"/>
</h4>
<ol>
<xsl:for-each select="key('uniqueOutputYearHeading',output_year)">
<xsl:for-each select="output_citation">
<xsl:if test="contains(translate(current(),$uppercase,$lowercase),translate($search,$uppercase,$lowercase))">
<li class="margin-bottom">
<xsl:copy-of select="current()"/>
</li>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</ol>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
But I am getting:
<h4>2011</h4>
<h4>2012</h4>
<ol>
<li>This is my title</li>
<li>This is also my title</li>
<li>This is another my title</li>
<h4>2014</h4>
<ol>
<li>This is my title</li>
</ol>
<h4>2015</h4>
I can't seem to get the 'contains' condition to work on the years, only the actual title. I've tried moving and duplicating it before the year heading but it returns nothing. Also I can't include a the search variable in the original key structure which would fix th eproblem (i think).