Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT increment variable

Tags:

People also ask

How do you increment a variable in XSLT?

You cannot increment a variable in xslt. you need to use xslt templates to achieve it.

How do you update a variable in XSLT?

Variables in XSLT are not really variables, as their values cannot be changed. They resemble constants from conventional programming languages. The only way in which a variable can be changed is by declaring it inside a for-each loop, in which case its value will be updated for every iteration.

How do you add a counter in XSLT?

XSLT is a functional language, not a procedural language, so you can't declare a counter. You can use xsl:number to get the position of the current node in its parent, if that helps. You can coerce a string to a number by using the XPath number() function.

How do you count nodes in XSLT?

Explanation: Using xsl:key , create a mapping from names to the nodes having that name. Then iterate through all unique names, and output the node count for the name. The main trick here is how to iterate through unique names. See the linked page for an explanation of the count(.


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>