首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用xslt用<i>替换<italic>

使用xslt用<i>替换<italic>
EN

Stack Overflow用户
提问于 2013-09-13 20:12:18
回答 2查看 75关注 0票数 0

我必须将元素"italic“转换为"i",我找到了一些解决方案,但当我将这些代码放入新的xsl文件中时,我从网站获得的这些解决方案是有效的,但如果我将其放入现有的xsl文件中,则不起作用。

我得到的解决方案是:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<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

EN

回答 2

Stack Overflow用户

发布于 2013-09-13 20:39:51

基本上,您需要确保在模板中保持对子节点的处理,因此需要在所有模板中使用<xsl:apply-templates/> (如果还希望转换或复制属性,则使用<xsl:apply-templates select="@* | node()"/> ),以匹配可以包含italic元素的元素。因此,您当然可以编写一个与root/ISSUES匹配的模板,但您需要通过执行<xsl:apply-templates/>来确保它保持对子对象的处理。

票数 1
EN

Stack Overflow用户

发布于 2013-09-13 20:54:42

添加

代码语言:javascript
复制
<xsl:template match="italic">
    <I>
        <xsl:apply-templates select="@* | node()"/>
    </I>
</xsl:template>

只有这样。属性和节点的处理将由代码的其余部分处理。该示例展示了如何在没有您自己的逻辑的情况下进行复制。然后,您的解决方案将如下所示:

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18786027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档