XSLT检查XML中的小时是否介于FromTime和EndTime之间



MY XML:

<Calendars xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Urnik.xsd">
    <Calendar>
        <Name>Robert T.</Name>
        <Days>
            <Day>
                <Date>2013-05-13</Date>
                <DayType>1</DayType>
                <DayWorking>1</DayWorking>
                <WorkingTimes>
                    <WorkingTime>
                        <FromTime>08:00</FromTime>
                        <ToTime>10:00</ToTime>
                        <Name>Izpit Matematika</Name>
                        <Owner>Robert T.</Owner>
                        <Category>
                            <School Professor="111" Room="1" Subject="882" />
                        </Category>
                    </WorkingTime>
                    <WorkingTime>
                        <FromTime>13:00</FromTime>
                        <ToTime>14:00</ToTime>
                        <Name>Vaje APZ</Name>
                        <Owner>Robert T.</Owner>
                        <Category>
                            <School Professor="222" Room="11" Subject="881"/>
                        </Category>
                    </WorkingTime>                  
                </WorkingTimes>
            </Day>
            <Day>

我的XSLT:

<xsl:variable name="n-rows" select="24"  />
    <xsl:template match="Calendars">
        ....
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="data">
            <xsl:call-template name="td-recursive" /> <!-- loop to get al day hours from 00:00 to 23:00)
        </table>    
        ...
        <xsl:template name="td-recursive">      
        <xsl:param name="index" select="1" />       
            <tr height="20px">
                <td align="center" class="tableRow" id="t1" width="5%">
                    <h3>Hour: <xsl:value-of select="concat(format-number($index - 1,'00'),':00')"  /></h3>                  
                </td>
                <xsl:for-each select="Calendar/Days/Day">
                    <xsl:if test="DayType = 1"> <!-- It is monday -->
                        <xsl:for-each select="WorkingTimes/WorkingTime">                            
                            <xsl:if test="Hour between FromTime and EndTime"> !-- PROBLEM -->
                                <td align="center" valign="top" class="classCell"></td>
                            </xsl:if>                           
                        </xsl:for-each>                             
                    </xsl:if>
                    ...
                </xsl:for-each>             
            </tr>
            <xsl:if test="$index &lt; $n-rows">
                <xsl:call-template name="td-recursive">
                <xsl:with-param name="index" select="$index + 1" />
            </xsl:call-template>
        </xsl:if>
    </xsl:template>

我想实现什么?

我想如果XML中的DayType是1,那么它就是星期一,我还想在正确的小时单元格中显示它。如果FromTime是08:00,ToTime是10:00,那么我需要在时间为08:00、09:00、10:00的行中打印结果

然后我如何检查<xsl:value-of select="concat(format-number($index - 1,'00'),':00')" />是否在FromTime和EndTime之间。如果是打印一些其他xml详细信息

检查是否有一些新东西可以为您提供

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="Calendar">
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="data">
            <xsl:call-template name="td-recursive">
                <xsl:with-param name="index" select="count(/Calendars/Calendar/Days/Day)"/>
                <!-- You can put 24-->
            </xsl:call-template>
        </table>
    </xsl:template>
    <xsl:template name="td-recursive">
        <xsl:param name="index"/>
        <xsl:if test="number($index) >= 1">
            <tr height="20px">
                <td align="center" class="tableRow" id="t0" width="5%">
                    <h3>Name: </h3>
                </td>
                <td align="center" class="tableRow" id="t1" width="5%">
                    <h3>Date: </h3>
                </td>
                <td align="center" class="tableRow" id="t2" width="5%">
                    <h3>Hour: <xsl:value-of select="concat(format-number($index - 1,'00'),':00')"/>
                    </h3>
                </td>
            </tr>
            <xsl:if test="Days/Day/DayType=1">
                <xsl:for-each select="Days/Day/WorkingTimes/WorkingTime">
                    <tr align="center" valign="top" class="classCell">
                        <td>
                            <xsl:value-of select="Name"/>
                        </td>
                        <td>
                            <xsl:value-of select="../../Date"/>
                        </td>
                        <td>
                            <xsl:call-template name="Hour">
                                <xsl:with-param name="FromTime" select="translate(FromTime,':','')"/>
                                <xsl:with-param name="ToTime" select="translate(ToTime,':','')"/>
                            </xsl:call-template>
                        </td>
                    </tr>
                </xsl:for-each>
            </xsl:if>
        </xsl:if>
    </xsl:template>
    <xsl:template name="Hour">
        <xsl:param name="FromTime"/>
        <xsl:param name="ToTime"/>
        <xsl:if test="$FromTime &lt;= $ToTime">
            <xsl:choose>
                <xsl:when test="string-length($FromTime) &lt; 4">
                    <xsl:value-of select="concat('0',substring($FromTime,1,1),':',substring($FromTime,2,2),', ')"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="concat(substring($FromTime,1,2),':',substring($FromTime,3,2),', ')"/>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:call-template name="Hour">
                <xsl:with-param name="FromTime" select="$FromTime + 0100"/>
                <xsl:with-param name="ToTime" select="$ToTime"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

相关内容

  • 没有找到相关文章

最新更新