I have the following XML
<data> <records> <record name="A record"> <info>A1</info> <info>A2</info> </record> <record name="B record"/> <record name="C record"> <info>C1</info> </record> </records> </data>
how can I transform into following output, the problem is how can I count between on record, and record/info?
<div id="1">
<p>A record</p>
<span id="1">A1</span>
<span id="2">A2</span>
</div>
<div id="2">
<p>C record</p>
<span id="3">C1</span>
</div>
Solution 1. Fine grained traversal. This stylesheet:
Output:
Solution 2:
preceding
axe. This stylesheet:Solution 3: With
fn:position()
andpreceding
axe. This stylesheet:Note: You need a explict pull style.
Edit: Missed any level numbering for span/@id.
There is a short way to do this in XSLT. Use the
<xsl:number>
instruction:When this transformation is applied on the provided XML document:
the wanted, correct result is produced: