I have a question about XSL transformation. Lets take an example (in srcML) which represents a typedef enum in C:
<typedef>typedef <type><enum>enum <name>SomeEnum</name>
<block>{
<expr><name>Value0</name> = 0</expr>,
<expr><name>Value1</name> = <name>SOMECONST</name></expr>,
<expr><name>Value2</name> = <name>SOMECONST</name> + 1</expr>,
<expr><name>ValueTop</name></expr>
}</block></enum></type> <name>TSomeEnum</name>;</typedef>
C version:
typedef enum SomeEnum
{
Value0 = 0,
Value1 = SOMECONST,
Value2 = SOMECONST + 1,
ValueTop
} TSomeEnum;
How to define an <xsl:template>
to remove the line with, for example, Value2
?
How to define an <xsl:template>
to remove the last line (with ValueTop
), including the preceding comma?
This is a bit tricky due to the "interspersed text" nature of your input XML. Especially comma handling is not trivial, and my proposed solution is probably wrong (even though it works for this particular input). I recommend giving the comma handling part a lot more thought since C syntax is complex and I don't know much about srcML.
Anyway, here is my attempt.
My input was (I used the srcML namespace for the sake of the example):
and the result: