I'm having a problem with XSL variables. I know that once declared, the value of the variable cant be changed.
But I'm facing a rather strange problem and I cant possibly change the XML output, instead figure out if its possible with XSL itself.
I'm using xsl:for-each to loop over some data in the XML.
The data being looped can be of three types, say Type1, Type2 and Type3
If it is of Type1, I'm calling a template to process that data. Inside the template I'm displaying a header. I need to print this header for the very first time I'm encountering this Type1 data only. After that I dont need to display this.
I could've passed a parameter along with the call-template and set/unset it to determine if I need to print the header text. But as I understand, being a formatting language, the variable state is not preserved.
Can you please provide your valuable suggestions on how to implement this(possibly without xml changes)?
Edit:
The test will work for the XML output mentioned by Patrice. But my XML is different.
<doc>
<item>foobar</item>
<item>foo</item>
<item>bar</item>
<item>baz</item>
<item>foo</item>
<item>bar</item>
</doc>
From this XML, I need to display a header for the very first time it encounters 'foo'. The order of items could be anything too. I cannot exactly predict when 'foo' will appear in the XML.
Can you please bring up any suggestions?