Svish
Svish

Reputation: 158231

XSLT axis for siblings across trees?

I am using XSLT to generate some webpages and I need to create links for the next and previous day. The structure is roughly as follows:

year
  month
    day
    day
    ...
  month
    day *
    day
    ...
  ...
...

Tried using the preceding-sibling and following-sibling axis, but then discovered they of course won't work for the first and last day of a month. For example preceding-sibling would return nothing for the day marked with *.

How can I get the previous and next day for a given day, across the year and month "barriers", using XSLT 1.0?

Upvotes: 1

Views: 34

Answers (1)

Tim C
Tim C

Reputation: 70638

The axis operators you are looking for in this case are preceding and following, which gets the preceding or following node regardless of the level in the hierarchy.

<xsl:copy-of select="following::day[1]" />

<xsl:copy-of select="preceding::day[1]" />  

Upvotes: 3

Related Questions