I've done quite a bit of searching and haven't quite been able to come up with anything yet using XSLT. I'm trying to take an XML template (for McPAT, partially shown below) dictating system specs and duplicate the 'component id="system.core0" name="core0"' node so I can have N core nodes. Each one will have to have "system.core#" as the id and "core#" as the name with # being the core number, 0-n.
I also have to duplicate this in any descendant nodes such as the system.core0.itlb node below.
Even further, in any of the descendant nodes with a value such as "config.system.cpu.clock", I have to append the node number to "cpu."
Finally, I have to overwrite 'param name="number_of_cores" value="1"' under system with 'param name="number_of_cores" value="n"' and change 'param name="homogenous_cores" value="1"' to 'param name="homogenous_cores" value="0"'
The XML currently looks like this:
<?xml version="1.0" ?>
<component id="root" name="root">
<component id="system" name="system">
<param name="number_of_cores" value="1"/>
<param name="homogeneous_cores" value="1"/>
<param name="number_of_L1Directories" value="0"/>
<param name="number_of_L2Directories" value="0"/>
<param name="number_of_L2s" value="1"/>
<param name="Private_L2" value="0"/>
<param name="number_of_L3s" value="0"/>
<param name="number_of_NoCs" value="1"/>
...
<component id="system.core0" name="core0">
<!-- Core property -->
<param name="clock_rate" value="{1e-6/config.system.cpu.clock*1e12}"/>
<param name="opt_local" value="1"/>
<stat name="total_instructions" value="{stats.system.cpu.iq.iqInstsIssued}"/>
...
<component id="system.core0.itlb" name="itlb">
<param name="number_entries" value="{config.system.cpu.itb.size}"/>
<stat name="total_accesses" value="{stats.system.cpu.itb.fetch_accesses}"/>
...
</component>
</component>
</component>
</component>
There are quite a few lines here. I've already gone and copied the system.core0 node N times, thanks to SO. I would post the link but I can't find the page. I do know that Dimitre Novatchev put the answer that I followed though and I'd like to give him credit for his help with that. So far, the XSLT stylesheet looks like this:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output indent="yes"/>
<xsl:param name="n" select="5"/>
<!--Identity template-->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="component[@id='system']/component[@name='core0']">
<xsl:call-template name="copyNtimes">
<xsl:with-param name="n" select="$n"/>
<xsl:with-param name="core_num" select="1"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="copyNtimes">
<xsl:param name="n" select="0"/>
<xsl:param name="core_num" select="1"/>
<xsl:if test="$n > 0">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
<xsl:text>
</xsl:text>
<xsl:call-template name="copyNtimes">
<xsl:with-param name="n" select="$n -1"/>
<xsl:with-param name="core_num" select="$core_num+1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
So at the end of running this through xsltproc, I have the original with system.core0 duplicated N times. What's left has been driving me crazy for days. How do I go about changing the core numbers for each new node I create, reflecting that in all child nodes as well? Any help at all would help, even if it's not code. I've played around with making new templates and using copy-of but nothing seems to be getting me closer.
I could also bring this all into another language such as Perl where I can run the XSLT stylesheet to duplicate change and manually modify the attribute strings if that'd be easier. I know Perl has some pretty good modules for both XML and XSLT. I feel that XSLT should be able to do this,though, and since I'm new to it, the format is throwing me off.
No comments:
Post a Comment