I am trying to convert XSLT that generates C code, the following XML should be converted:
<enum name="anenum"> <enumValue name="a"/> <enumValue name="b"/> <enumValue name="c" data="10"/> <enumValue name="d" /> <enumValue name="e" /> </enum>
It should convert to some C code as follows:
enum anenum { a = 0, b = 1, c = 10, d = 11, e = 12 }
or alternatively (since the C preprocessor handles the summation):
enum anenum { a = 0, b = 1, c = 10, d = c+1, e = c+2 }
The core of my XSLT looks like this:
<xsl:for-each select="enumValue"> <xsl:value-of select="name"/> <xsl:text> = </xsl:text> <xsl:choose> <xsl:when test="string-length(@data)>0"> <xsl:value-of select="@data"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="position()-1"/> </xsl:otherwise> </xsl:choose> <xsl:text>,
(for simplicity, I skip the "no comma at the last element" code part)
In this example, the correct values ββfor d and e will not be created.
I am trying to get it to work with the variable d and e , but so far I have not been successful.
The use of structures such as:
<xsl:when test="string-length(preceding-sibling::enumValue[1]/@datavalue)>0"> <xsl:value-of select="preceding-sibling::enumValue/@data + 1"/> </xsl:when>
... only works for the first after the specified value (in this case, d ).
Who can help me? I probably think too much in procedural form ...