Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

How to get the previous element in a sorted for-each loop

Avatar of pnr_dk
pnr_dk asked on
Web Languages and StandardsXML
25 Comments1 Solution550 ViewsLast Modified:
I need to access the previous element in my sorted for-each loop. It is no problem if I don’t use sorting then it works fine.

Example:

<Timetable>
  <Result>
        .....
        </TimetableEvent>
        <TimetableEvent>
            <Date>2010-06-15</Date>
            <WeekNumber>24</WeekNumber>
            <WeekdayNumber>2</WeekdayNumber>
            <Weekday>Tirsdag</Weekday>
            <LectureNumber>6</LectureNumber>
            <StartTime>13:30</StartTime>
            <EndTime>14:15</EndTime>
            <Subject>
                <SubjectName>63040</SubjectName>
                <Level>-</Level>
                <ShortDescription>Modul 4</ShortDescription>
                <Description>Beskrivelse</Description>
            </Subject>
            <Activity>
                <Name>EH75</Name>
                <ShortDescription>E75</ShortDescription>
                <Description>beskrivelse</Description>
                <Department>EH</Department>
                <NumberOfActiveStudents>39</NumberOfActiveStudents>
            </Activity>
            <Room>
                <Number>204 Teo</Number>
                <ShortDescription>kort...</ShortDescription>
                <Name>et eller andet</Name>
                <Role>U</Role>
                <RoleType>U</RoleType>
                <BuildingNumber>hus</BuildingNumber>
                <BuildingDescription>stort hus</BuildingDescription>
            </Room>
        </TimetableEvent>
        <TimetableEvent>
        .....
  </Result>
</Timetable>

<!--Getting data-->
          <xsl:variable name="skema" select="/Result/Timetable/TimetableEvent[generate-id(.) = generate-id(key('t', StartTime))]"></xsl:variable>

<!-- loop -->
    <xsl:for-each select="$skema[(number(substring-before(StartTime,':'))*100+number(substring-after(StartTime,':'))) > 799]">
                <xsl:sort select="number(substring-before(StartTime,':'))*100+number(substring-after(StartTime,':'))" data-type="number" order="ascending"/>

<!-- current endtime -->
<xsl:value-of select="EndTime"/> -

<!-- *** previous starttime, this isn't working *** -->
<xsl:value-of select="./preceding-sibling::node()[1]/StartTime"></xsl:value-of> 

...

Thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)Flag of Belgium imageInformation Architect
Commented:
This problem has been solved!
Unlock 1 Answer and 25 Comments.
See Answers