I have a simple task that I can’t find a solution for, and I’m new enough to xsl that I don’t how to go about it. I have a list of nodes, and at the first occurrence of the nodes I would like to print a header. E.g.:
xml excerpt
<data>
<subdata1>value1.1</subdata1>
<subdata2>value1.2</subdata2>
</data>
<data>
<subdata1>value2.1</subdata1>
<subdata2>value2.2</subdata2>
</data>
<data>
<subdata1>value3.1</subdata1>
<subdata2>value3.2</subdata2>
</data>
I would like the output to be something like:
Subdata1 Subdata2
value1.1 value2.1
value2.1 value2.2
value3.1 value2.3
There will be stuff before the first “data” node, so I don’t think I can just print it out ahead of time. I was thinking of an if statement with a flag that would be set the first time it finds data, but my implementation wasn’t working. Any ideas on how to do this?
Thanks!
This transformation:
when applied on the following XML document (the provided XML fragment, wrapped into a single top element to become a well-formed XML document):
produces the wanted, correct result:
Explanation: Appropriate use of templates and modes.