我必须将元素"italic“转换为"i",我找到了一些解决方案,但当我将这些代码放入新的xsl文件中时,我从网站获得的这些解决方案是有效的,但如果我将其放入现有的xsl文件中,则不起作用。
我得到的解决方案是:
<xsl:template match="italic">
<I>
<xsl:apply-templates select="@* | node()"/>
</I>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>但是我有以下的xsl:
<xsl:template match="/">
<xsl:message>Inside root</xsl:message>
<xsl:apply-templates select="/root/ISSUES" />
</xsl:template>
<xsl:template match="/root/ISSUES">
some logic follows here( it might even internally call many templates)
</xsl:template>谁能告诉我在这个xsl中把解决方案(首先给出的代码)放在哪里?
谢谢,Shyam
发布于 2013-09-13 20:39:51
基本上,您需要确保在模板中保持对子节点的处理,因此需要在所有模板中使用<xsl:apply-templates/> (如果还希望转换或复制属性,则使用<xsl:apply-templates select="@* | node()"/> ),以匹配可以包含italic元素的元素。因此,您当然可以编写一个与root/ISSUES匹配的模板,但您需要通过执行<xsl:apply-templates/>来确保它保持对子对象的处理。
发布于 2013-09-13 20:54:42
添加
<xsl:template match="italic">
<I>
<xsl:apply-templates select="@* | node()"/>
</I>
</xsl:template>只有这样。属性和节点的处理将由代码的其余部分处理。该示例展示了如何在没有您自己的逻辑的情况下进行复制。然后,您的解决方案将如下所示:
<xsl:template match="/">
<xsl:message>Inside root</xsl:message>
<xsl:apply-templates select="/root/ISSUES" />
</xsl:template>
<xsl:template match="/root/ISSUES">
some logic follows here( it might even internally call many templates)
</xsl:template>
<xsl:template match="italic">
<I>
<xsl:apply-templates select="@* | node()"/>
</I>
</xsl:template>https://stackoverflow.com/questions/18786027
复制相似问题