我想在xslt 1.0中執行sipmle'Muenchian分組',但也要從不同節點添加通配符搜索。在XSLT 1.0中使用通配符搜索進行分組
我很熟悉分組方法,它的工作很好,但在通配符問題上遇到問題,因爲它總是顯示沒有通配符搜索的組標題。
這裏是我的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>
我想下面給出字符串 '我' 的通配符SEACH輸出:
<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>
所以標題 '2011' 和 '2015年'不應該出現(但他們做,這就是問題所在)
這裏是我的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>
但我得到:
<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>
我似乎無法得到「包含」條件對多年工作,只有實際的稱號。我試過在年頭前移動並複製它,但它什麼也沒有返回。另外,我不能在原來的關鍵結構中包含一個搜索變量來解決這個問題(我認爲)。
這兩種方法都有效。非常感謝 – kevmull 2015-02-23 16:57:12