0

XML:

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

XSLT:

<xsl:for-each select="Calendar/Days/Day">   
    <xsl:choose>
        <xsl:when test="DayType = 1">
            <xsl:variable name="vTransfers" select="child::*/WorkingTime"/>                 

我可以以某种方式检查此变量vTransfers是否08:00存在于FromTime. 我不想循环它,因为我需要将它放在正确的TD行中。我现在在这个 TD 中,我想检查这个数组中是否08:00存在FromTime

我尝试类似

<xsl:when test="contains($vTransfers/ToTime, '08:00')">
                        <xsl:text>IN</xsl:text>
                    </xsl:when>
                    <xsl:otherwise>                                     
                        <xsl:text>OUT</xsl:text>
                    </xsl:otherwise>

但总是只取第一个而不检查整个数组。

4

1 回答 1

3

如果您将节点集传递给contains,它将被转换为字符串。这意味着只取第一个节点的字符串值。尝试这样的事情:

<xsl:when test="$vTransfers[contains(ToTime, '08:00')]">

这也应该有效:

<xsl:when test="WorkingTimes/WorkingTime/ToTime = '08:00'">
于 2013-08-22T09:21:21.103 回答