How to get a proceeding item that may be in another node?


With the sample XML:


I am currently rendering out a spreadsheet that essentially makes a top level. I'm doing this through an apply-templates, where I have

<apply-templates match="orders/order/items/item"><!-- sorts --></apply-templates>

I want to apply a header whenever a certain attribute in the item changes, how would I get the previous item?

for item4, I think I could use preceding-sibling::item to get item3, but if my active node was item3, how would I get item2?

I'm currently assuming I'll need to set this to a variable with a choose, something like:

<xslt:variable name="previousItem">
        <xslt:when test="count(preceding-sibling::item)">
            <xslt:value-of match="preceding-sibling::item" />
            <!-- some logic here -->

Show source
| xml   | xslt   2016-12-12 20:12 1 Answers

Answers ( 1 )

  1. 2016-12-12 21:12

    Try preceding::item[1]. It only selects items that occurs before the current element.

◀ Go back