What this should do is walk back up to the first EventSessionFolder node with a sessionType of 'break'. It should then count all EventSessionFolders between the Break and the Current Session Folder. It should not include the current session folder in the count.
Here is some sample XML:
<Event>
<EventSessionFolder>
<sessionType>Session type 1</sessionType>
</EventSessionFolder>
<EventSessionFolder>
<sessionType>Session type 2</sessionType>
</EventSessionFolder>
<EventSessionFolder>
<sessionType>Break</sessionType>
</EventSessionFolder>
<EventSessionFolder>
<sessionType>Session type 3</sessionType>
</EventSessionFolder>
<EventSessionFolder>
<sessionType>Session type 4</sessionType>
</EventSessionFolder>
<EventSessionFolder>
<sessionType>Session type 5</sessionType>
</EventSessionFolder>
</Event>
Expected result:
If I was currently in the EventSessionFolder in bold above, the corect count should be two i.e 2 EventSessionFolders after the break and before the current EventSessionFolder.
I hope someone can enlighten me as to what I am missing here?
Looking over the logic... is the example XML missing "id" attributes from the "EventSessionFolder" nodes? (curious if these are Umbraco nodes, or general XML?)
Initially your XPath looks correct, but would need to test/play with it.
Just saw this and wanted to chip in (don't know if you managed to solve it already).
The problem with the XPath you're using is that it only works as long as your 'current' is the last one - that may always be the case, but the day it isn't, you'll probably begin tearing out that precious hair of yours :-)
Here's an alternate calculation that makes sure to only use the nodes between the 'Break' and 'current':
<!-- Grab the equivalent of position() for the Break node -->
<xsl:variable name="breakpos" select="1 + count(preceding-sibling::EventSessionFolder[sessionType = 'Break'][1]/preceding-sibling::EventSessionFolder)" />
<!-- Count the nodes between -->
<xsl:value-of select="count(preceding-sibling::EventSessionFolder[position() > $breakpos])" />
Because of time restrictions I had to cheat a little by using javascript to assist in achieving the end goal however it was bugging me that I could get so close and yet still not solve this so thanks for the contribution and I will be sure to see if it solves my problem and allows me to remove my javascript *hack*.
Count nodes Between a previous sibling and current node
I've been fighting with this for a while now and I think I can no longer spot the obvious, hopefully someone else can!?
Here is my current XPath which returns the same result for each node I attempt it on and so therefore is wrong somehow:
What this should do is walk back up to the first EventSessionFolder node with a sessionType of 'break'. It should then count all EventSessionFolders between the Break and the Current Session Folder. It should not include the current session folder in the count.
Here is some sample XML:
Expected result:
If I was currently in the EventSessionFolder in bold above, the corect count should be two i.e 2 EventSessionFolders after the break and before the current EventSessionFolder.
I hope someone can enlighten me as to what I am missing here?
Simon
Hi Simon,
Looking over the logic... is the example XML missing "id" attributes from the "EventSessionFolder" nodes? (curious if these are Umbraco nodes, or general XML?)
Initially your XPath looks correct, but would need to test/play with it.
Cheers, Lee.
Hang fire - I think I found the issue elsewhere in my XSLT. Coming back to it with a fresh pair of eyes in the morning.
It is Umbraco XML, I just hand crafted the example above so the standard attributes are missing in the example, sorry.
Thanks for validating my logic - good to know that it looked correct :)
Cheers, Si
Hi Simon,
Just saw this and wanted to chip in (don't know if you managed to solve it already).
The problem with the XPath you're using is that it only works as long as your 'current' is the last one - that may always be the case, but the day it isn't, you'll probably begin tearing out that precious hair of yours :-)
Here's an alternate calculation that makes sure to only use the nodes between the 'Break' and 'current':
/Chriztian
Hi Chriztian,
Because of time restrictions I had to cheat a little by using javascript to assist in achieving the end goal however it was bugging me that I could get so close and yet still not solve this so thanks for the contribution and I will be sure to see if it solves my problem and allows me to remove my javascript *hack*.
Thanks again.
Simon
is working on a reply...