0

我的 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 详细信息

4

1 回答 1

0

检查有一些新的东西应该为你服务

<?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>
于 2013-08-20T14:19:19.183 回答