mbrc
mbrc

Reputation: 3973

XSLT how to store values in array

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="/*/WorkingTime"/>
            <xsl:value-of select="$vTransfers[1]" />

I am looping Day nodes. And then I want to store all WorkingTime nodes from DayType = 1 to array. Not loop it but store it in array because I will print it later in the correct td tag

But is empty but I expect to get:

<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>

Can you give me some clue how?

Upvotes: 0

Views: 2207

Answers (2)

jvverde
jvverde

Reputation: 631

I am not sure if I understand what you want, but to get a variable with wall all WorkingTime nodes from DayType = 1 you can declare a variable as this

<xsl:variable name="vTransfers" select="//Day[DayType=1]/WorkingTimes/WorkingTime"/>

Edited:

The above code can be used anywhere in you code and you get all the WorkingTime element in all your Day element.

However, to use it inside your for-each cycle and only get the WorkingTime of the current Day you can change it to

<xsl:variable name="vTransfers" select="self::Day[DayType=1]/WorkingTimes/WorkingTime"/>

Upvotes: 2

dperez
dperez

Reputation: 101

Change the variable in select to "child::*/WorkingTime" I recommend you use Altova XMLSpy and so you can use one of the many features it has such as debugging, to see the results.

Upvotes: 1

Related Questions