我正在尝试比较星期一的AvailabilityStartTimeMeasure
和AvailabilityEndTimeMeasure
与剩余时间。
DaysOfWeek
和AvailabilityStartTimeMeasure
以及AvailabilityEndTimeMeasure
。XML:
<HoursOfOperation>
<HoursTypeCode>Sales</HoursTypeCode>
<DaysOfWeek>
<DayOfWeekCode>Monday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">510</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1140</AvailabilityEndTimeMeasure>
</DaysOfWeek>
<DaysOfWeek>
<DayOfWeekCode>Tuesday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">510</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1140</AvailabilityEndTimeMeasure>
</DaysOfWeek>
<DaysOfWeek>
<DayOfWeekCode>Wednesday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">510</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1140</AvailabilityEndTimeMeasure>
</DaysOfWeek>
<DaysOfWeek>
<DayOfWeekCode>Thursday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">510</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1140</AvailabilityEndTimeMeasure>
</DaysOfWeek>
<DaysOfWeek>
<DayOfWeekCode>Friday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">510</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1140</AvailabilityEndTimeMeasure>
</DaysOfWeek>
<DaysOfWeek>
<DayOfWeekCode>Saturday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">600</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1080</AvailabilityEndTimeMeasure>
</DaysOfWeek>
<DaysOfWeek>
<DayOfWeekCode>Sunday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">660</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1080</AvailabilityEndTimeMeasure>
</DaysOfWeek>
</HoursOfOperation>
XSLT:
<xsl:for-each select="DaysOfWeek">
<xsl:if test="position() > 1">
<xsl:choose>
<xsl:when test="($StartTime = AvailabilityStartTimeMeasure) and ($EndTime = AvailabilityEndTimeMeasure)">
</xsl:when>
<xsl:otherwise>
<xsl:variable name="pnode"><xsl:value-of select="(preceding-sibling::*[DayOfWeekCode])[last()]" /></xsl:variable>
<xsl:value-of select="$pnode" />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
现在正在打印
周五510 1140周六600 1080
我只想在星期六星期六展示。我怎么需要修改前兄弟姐妹才能获得周五和周六。
答案 0 :(得分:0)
您的方法的问题是每当测试为真时输出结果;你应该等到测试失败,然后用前面天的名字关闭字符串。
可能有一种更好的方法可以做到这一点,但我不确定我是否理解逻辑:你是否会每天重复这个测试&lt;星期日?如果比赛是{周一,周三,周五,周日}和{周二,周四,周六}怎么办?
<强>附录强>:
假设我们希望按照可用时间对天数进行分组,无论是否连续,以下样式表都使用Muenchian分组方法来实现:
<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="similarDays"
match="DaysOfWeek"
use="concat(AvailabilityStartTimeMeasure, '|', AvailabilityEndTimeMeasure)" />
<xsl:template match="/">
<table>
<xsl:for-each select="HoursOfOperation/DaysOfWeek[count(. | key('similarDays', concat(AvailabilityStartTimeMeasure, '|', AvailabilityEndTimeMeasure))[1]) = 1]">
<tr>
<td>
<xsl:for-each select="key('similarDays', concat(AvailabilityStartTimeMeasure, '|', AvailabilityEndTimeMeasure))">
<xsl:value-of select="DayOfWeekCode"/>
<xsl:if test="position()!=last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
</td>
<td style="text-align:right;">
<xsl:call-template name="minutes2time">
<xsl:with-param name="minutes" select="AvailabilityStartTimeMeasure"/>
</xsl:call-template>
<xsl:text> - </xsl:text>
<xsl:call-template name="minutes2time">
<xsl:with-param name="minutes" select="AvailabilityEndTimeMeasure"/>
</xsl:call-template>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template name="minutes2time">
<xsl:param name="minutes"/>
<xsl:param name="h" select="floor($minutes div 60)"/>
<xsl:param name="m" select="$minutes mod 60"/>
<xsl:param name="pad" select="substring('0', 1, $m < 10)"/>
<xsl:value-of select="concat($h, ':', $pad, $m)"/>
</xsl:template>
</xsl:stylesheet>
应用于原始示例,这将生成以下输出:
<?xml version="1.0" encoding="utf-8"?>
<table>
<tr>
<td>Monday, Tuesday, Wednesday, Thursday, Friday</td>
<td style="text-align:right;">8:30 - 19:00</td>
</tr>
<tr>
<td>Saturday</td>
<td style="text-align:right;">10:00 - 18:00</td>
</tr>
<tr>
<td>Sunday</td>
<td style="text-align:right;">11:00 - 18:00</td>
</tr>
</table>
呈现为:
Monday, Tuesday, Wednesday, Thursday, Friday 8:30 - 19:00
Saturday 10:00 - 18:00
Sunday 11:00 - 18:00
以以下形式应用于修改后的输入:
<HoursOfOperation>
<HoursTypeCode>Sales</HoursTypeCode>
<DaysOfWeek>
<DayOfWeekCode>Monday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">510</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1140</AvailabilityEndTimeMeasure>
</DaysOfWeek>
<DaysOfWeek>
<DayOfWeekCode>Tuesday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">510</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1140</AvailabilityEndTimeMeasure>
</DaysOfWeek>
<DaysOfWeek>
<DayOfWeekCode>Wednesday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">660</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1080</AvailabilityEndTimeMeasure>
</DaysOfWeek>
<DaysOfWeek>
<DayOfWeekCode>Thursday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">510</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1140</AvailabilityEndTimeMeasure>
</DaysOfWeek>
<DaysOfWeek>
<DayOfWeekCode>Friday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">600</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1200</AvailabilityEndTimeMeasure>
</DaysOfWeek>
<DaysOfWeek>
<DayOfWeekCode>Saturday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">660</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1080</AvailabilityEndTimeMeasure>
</DaysOfWeek>
<DaysOfWeek>
<DayOfWeekCode>Sunday</DayOfWeekCode>
<AvailabilityStartTimeMeasure unitCode="minute">660</AvailabilityStartTimeMeasure>
<AvailabilityEndTimeMeasure unitCode="minute">1080</AvailabilityEndTimeMeasure>
</DaysOfWeek>
</HoursOfOperation>
(渲染)输出将是:
Monday, Tuesday, Thursday 8:30 - 19:00
Wednesday, Saturday, Sunday 11:00 - 18:00
Friday 10:00 - 20:00
答案 1 :(得分:0)
根据我对您的问题的理解,如果DayofWeekCode
和$StartTime
与当前$EndTime
和AvailabilityStartTimeMeasure
不匹配,您会希望显示AvailabilityEndTimeMeasure
在循环。
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="StartTime" select="/HoursOfOperation/DaysOfWeek[1]/AvailabilityStartTimeMeasure[1]"/>
<xsl:variable name="EndTime" select="/HoursOfOperation/DaysOfWeek[1]/AvailabilityEndTimeMeasure[1]"/>
<xsl:template match="HoursOfOperation">
<xsl:for-each select="DaysOfWeek">
<xsl:if test="position() > 1">
<xsl:choose>
<xsl:when test="($StartTime != AvailabilityStartTimeMeasure) and ($EndTime != AvailabilityEndTimeMeasure)">
<xsl:choose>
<xsl:when test="position()!=last()">
<xsl:value-of select="DayOfWeekCode"/><xsl:text> </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="DayOfWeekCode"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
输出
Saturday Sunday
因为它们与$StartTime
和$EndTime