1 <xsl:stylesheet version="1.0"
2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3 <xsl:variable name="total" select="count(//reg)"/>
4 <xsl:template name="reg">
5 <xsl:param name="which" select="1"/>
6 <xsl:param name="nextnum" select="0"/>
7 <xsl:variable name="thisnum" select="@regnum"/>
8 <xsl:element name="reg">
9 <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
10 <xsl:attribute name="bitsize"><xsl:value-of select="@bitsize"/></xsl:attribute>
12 <xsl:when test="not(@regnum)">
13 <xsl:attribute name="regnum"><xsl:value-of select="$nextnum"/></xsl:attribute>
16 <xsl:attribute name="regnum"><xsl:value-of select="@regnum"/></xsl:attribute>
20 <xsl:if test="$which < $total">
21 <xsl:for-each select="/descendant::reg[$which + 1]">
23 <xsl:when test="not($thisnum)">
24 <xsl:call-template name="reg">
25 <xsl:with-param name="which" select="$which + 1"/>
26 <xsl:with-param name="nextnum" select="$nextnum + 1"/>
30 <xsl:call-template name="reg">
31 <xsl:with-param name="which" select="$which + 1"/>
32 <xsl:with-param name="nextnum" select="$thisnum + 1"/>
40 <xsl:template match="/">
42 <xsl:for-each select="/descendant::reg[1]">
43 <xsl:call-template name="reg"/>