I'm using XSLT to convert 2 XML files into C code (XSLT 2.0).
The goal is to generate the #include
required for the .c file (could be many).
There are 2 different places I need to look for the variable portion of the #include
name: one can be read straight from one XML file, but the second needs to search the other file once we have found the first (both are generated XML files, yay for inherited code!).
<xsl:for-each select="/root/eventDoc/event/parameterList/parameter">
<xsl:variable name="name" select="@name"/>
<xsl:variable name="module" select="@module"/>
<xsl:variable name="refModule" select="eventgen:ref-module-lookup($name, $module)"/>
Currently I simply print $module
and $refModule
in an include like so (simplified by removing my current work to avoid duplicates):
<xsl:text>
#include "agent/gen/</xsl:text><xsl:value-of select="concat(fn:lower-case(translate($module, '-', '_')),'.h')"/><xsl:text>"</xsl:text>
This works okay, but I want to get rid of the inevitable duplicates.
If I was simply writing C code, I would create an array and add each unique $module
and $refModule
and then walk through it and print each out.
My first approach had me using preceding::parameter/@module
to avoid duplicates, the problem is that preceding::parameter/@refModule
doesn't exist because it doesn't belong to this XML file! preceding::parameter/$refModule
didn't work either (not 100% clear on variable scope in XSLT).
I think I can deal with the unique part, but my question is how can I store these non-XML values so that I can go through them after my for-each
and print them out? Templates? Perhaps I don't need to store after all?
Note: I can provide XML input, but I don't think it would be helpful for my question (let me know)
Thanks!
Edit: While already solved, adding some additional information for any unlucky person who has a similar problem.
Input XML one:
<event name="PolicyError">
<!-- list of parameters -->
<parameterList>
<parameter
name="Index" module="COMPANY-TEAM-NG-MIB"
/>
<parameter
name="PolicyId" module="COMPANY-TEAM-NG-MIB"
/>
</parameterList>
</event>
desired output:
#include "agent/gen/company_team_ng_mib.h"
In the interest of simplicity, I've left out the eventgen:ref-module-lookup
function and the second XML file, but it basically uses the given name
and module
to lookup the root module
(refModule
) in which name
is defined