With the sample XML:
<orders> <order> <items> <item>1</item> <item>2</item> </items> </order> <order> <items> <item>3</item> <item>4</item> </items> </order> </orders>
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:choose> <xslt:when test="count(preceding-sibling::item)"> <xslt:value-of match="preceding-sibling::item" /> </xslt:when> <xslt:otherwise> <!-- some logic here --> </xslt:otherwise> </xslt:choose> </xslt:variable>