我很难弄清楚如何在这个示例中合并日期单元格。
因此,我在上一个问题xsl-if-condition-with-text-or-image中的xml中的以下日期是这样的:
<?xml version="1.0" encoding="utf-8"?>
<weeklyevents>
<event>
<title>AIG Services Index</title>
<country>AUD</country>
<date><![CDATA[05-04-2014]]></date>
</event>
<event>
<title>Bank Holiday</title>
<country>JPY</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>MI Inflation Gauge m/m</title>
<country>AUD</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>ANZ Job Advertisements m/m</title>
<country>AUD</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Building Approvals m/m</title>
<country>AUD</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>HSBC Final Manufacturing PMI</title>
<country>CNY</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Bank Holiday</title>
<country>GBP</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Sentix Investor Confidence</title>
<country>EUR</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>EU Economic Forecasts</title>
<country>EUR</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>PPI m/m</title>
<country>EUR</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Eurogroup Meetings</title>
<country>EUR</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Final Services PMI</title>
<country>USD</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>ISM Non-Manufacturing PMI</title>
<country>USD</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Loan Officer Survey</title>
<country>USD</country>
<date><![CDATA[05-05-2014]]></date>
</event>
<event>
<title>Bank Holiday</title>
<country>JPY</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Trade Balance</title>
<country>AUD</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Cash Rate</title>
<country>AUD</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>RBA Rate Statement</title>
<country>AUD</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Spanish Unemployment Change</title>
<country>EUR</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Spanish Services PMI</title>
<country>EUR</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Italian Services PMI</title>
<country>EUR</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Final Services PMI</title>
<country>EUR</country>
<date><![CDATA[05-06-2014]]></date>
</event>
<event>
<title>Services PMI</title>
<country>GBP</country>
<date><![CDATA[05-06-2014]]></date>
</event>
</weeklyevents>
我的xsl代码是这样的:
<xsl:template match="/">
<table class="headingstable">
<tr>
<th class="headingstop">Title</th>
<th class="headingstop">Country</th>
<th class="headingstop">Date</th>
</tr>
<xsl:for-each select="weeklyevents/event">
<tr>
<td class="headingsmid"><xsl:value-of select="title"/></td>
<td class="headingsmid"><xsl:value-of select="country"/></td>
<td class="headingsmid"><xsl:value-of select="date"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
预期结果应该与我上面发布的图片相似。所以我想只合并相同的日期。也许是这样的 05-06-2014
是否可以将日期转换为其他格式,例如 Thur 05-May 或星期四05-06 ,而不是 05-06-2014
任何想法如何做到这一点?
由于
答案 0 :(得分:1)
从那时起我已经尝试了几个小时但仍然没有真正工作..我 需要帮助!!
以此为出发点:
XSLT 1.0
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="events-by-date" match="event" use="date" />
<xsl:template match="/">
<table>
<!-- for each distinct date -->
<xsl:for-each select="weeklyevents/event[count(. | key('events-by-date', date)[1]) = 1]">
<tr>
<th><xsl:value-of select="date"/></th>
</tr>
<!-- get events on this date -->
<xsl:for-each select="key('events-by-date', date)">
<tr>
<td><xsl:value-of select="title"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>