我还必须在任何后代节点中复制它,例如下面的system.core0.itlb节点.
更进一步,在具有诸如“config.system.cpu.clock”之类的值的任何后代节点中,我必须将节点号附加到“cpu”.
最后,我必须覆盖
param name =“number_of_cores”value =“1”
在系统下
param name =“number_of_cores”value =“n”
并改变
param name =“homogenous_cores”value =“1”
至
param name =“homogenous_cores”value =“0”
XML目前看起来像这样:
<?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>
这里有很多行.我已经离开并复制了system.core0节点N次,多亏了SO.我会发布链接,但我找不到页面.我知道Dimitre Novatchev提出了我所遵循的答案,我想对他的帮助表示赞赏.到目前为止,XSLT样式表看起来像这样:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <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>
所以在通过xsltproc运行它的最后,我有原始的system.core0重复N次.剩下的东西让我疯狂了好几天.如何更改我创建的每个新节点的核心编号,反映在所有子节点中?任何帮助都会有所帮助,即使它不是代码.我已经玩过制作新模板和使用副本,但似乎没有什么能让我更接近.
我也可以将这些全部带入另一种语言,例如Perl,我可以运行XSLT样式表来复制更改并手动修改属性字符串,如果这样更容易的话.我知道Perl有一些非常好的模块用于XML和XSLT.我觉得XSLT应该能够做到这一点,而且由于我是新手,因此格式让我失望.
编辑:
我需要的示例输出是这样的:
<?xml version="1.0" ?> <component id="root" name="root"> <component id="system" name="system"> <param name="number_of_cores" value="3"/> <param name="homogeneous_cores" value="0"/> <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.cpu0.clock*1e12}"/> <param name="opt_local" value="1"/> <stat name="total_instructions" value="{stats.system.cpu0.iq.iqInstsIssued}"/> <!--...--> <component id="system.core0.itlb" name="itlb"> <param name="number_entries" value="{config.system.cpu0.itb.size}"/> <stat name="total_accesses" value="{stats.system.cpu0.itb.fetch_accesses}"/> ... </component> </component> <component id="system.core1" name="core1"> <!-- Core property --> <param name="clock_rate" value="{1e-6/config.system.cpu1.clock*1e12}"/> <param name="opt_local" value="1"/> <stat name="total_instructions" value="{stats.system.cpu1.iq.iqInstsIssued}"/> <!--...--> <component id="system.core1.itlb" name="itlb"> <param name="number_entries" value="{config.system.cpu1.itb.size}"/> <stat name="total_accesses" value="{stats.system.cpu1.itb.fetch_accesses}"/> ... </component> </component><component id="system.core2" name="core2"> <!-- Core property --> <param name="clock_rate" value="{1e-6/config.system.cpu2.clock*1e12}"/> <param name="opt_local" value="1"/> <stat name="total_instructions" value="{stats.system.cpu2.iq.iqInstsIssued}"/> <!--...--> <component id="system.core2.itlb" name="itlb"> <param name="number_entries" value="{config.system.cpu2.itb.size}"/> <stat name="total_accesses" value="{stats.system.cpu2.itb.fetch_accesses}"/> ... </component> </component> </component> </component>
<xsl:template match="param[@name='number_of_cores' and @value='1']"> <param name="number_of_cores" value="{$n}"/> </xsl:template> <xsl:template match="param[@name='homogeneous_cores' and @value='1']"> <param name="homogenous_cores" value="0"/> </xsl:template>
您将覆盖标识转换,并能够输出不同的参数元素,如上所示.
(2)如果您在copyNtimes内调整复制如下,
<xsl:copy> <xsl:attribute name="id" select="concat('system.core',$n)"/> <xsl:attribute name="name" select="concat('core',$n)"/> <xsl:apply-templates select="node()"/> </xsl:copy>
你将生成非碳复制品,但副本中@id和@name反映传递给copyNtimes的拷贝数.
(3)如果你在copyNtimes中进一步调整xsl:apply-template到隧道n(需要XSLT 2.0),
<xsl:apply-templates select="node()"> <xsl:with-param name="compNum" tunnel="yes" select="$n"/> </xsl:apply-templates>
并添加一个模板来处理隧道另一侧的itlb组件,
<xsl:template match="component[@name='itlb']"> <xsl:param name="compNum" tunnel="yes"/> <component name="itlb" value="{concat('system.core',$compNum,'.itlb')}"> <xsl:apply-templates/> </component> </xsl:template>
您可以将组件编号工作到后代itlb组件中.
这个输入XML文档:
<?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>
鉴于此XSLT转换:
<?xml version="1.0"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <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="param[@name='number_of_cores' and @value='1']"> <param name="number_of_cores" value="{$n}"/> </xsl:template> <xsl:template match="param[@name='homogeneous_cores' and @value='1']"> <param name="homogenous_cores" value="0"/> </xsl:template> <xsl:template match="component[@name='itlb']"> <xsl:param name="compNum" tunnel="yes"/> <component name="itlb" value="{concat('system.core','.itlb')}"> <xsl:apply-templates/> </component> </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:attribute name="id" select="concat('system.core',$n)"/> <xsl:attribute name="name" select="concat('core',$n)"/> <xsl:apply-templates select="node()"> <xsl:with-param name="compNum" tunnel="yes" select="$n"/> </xsl:apply-templates> </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>
将产生此输出XML文档:
<?xml version="1.0" encoding="UTF-8"?> <component id="root" name="root"> <component id="system" name="system"> <param name="number_of_cores" value="5"/> <param name="homogenous_cores" value="0"/> <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.core5" name="core5"> <!-- 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 name="itlb" value="system.core5.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 id="system.core4" name="core4"> <!-- 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 name="itlb" value="system.core4.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 id="system.core3" name="core3"> <!-- 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 name="itlb" value="system.core3.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 id="system.core2" name="core2"> <!-- 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 name="itlb" value="system.core2.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 id="system.core1" name="core1"> <!-- 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 name="itlb" value="system.core1.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>