首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对一组标记进行优化<xsl:apply-templates/>

对一组标记进行优化<xsl:apply-templates/>
EN

Stack Overflow用户
提问于 2010-04-13 09:49:51
回答 2查看 683关注 0票数 2

如何减少这个记录?

代码语言:javascript
复制
<xsl:template match="BR">
    <br/>
</xsl:template>

<xsl:template match="B">
    <strong><xsl:apply-templates /></strong>
</xsl:template>

<xsl:template match="STRONG">
    <strong><xsl:apply-templates /></strong>
</xsl:template>

<xsl:template match="I">
    <em><xsl:apply-templates /></em>
</xsl:template>

<xsl:template match="EM">
    <em><xsl:apply-templates /></em>
</xsl:template>

<xsl:template match="OL">
    <ol><xsl:apply-templates /></ol>
</xsl:template>

<xsl:template match="UL">
    <ul><xsl:apply-templates /></ul>
</xsl:template>

<xsl:template match="LI">
    <li><xsl:apply-templates /></li>
</xsl:template>

<xsl:template match="SUB">
    <sub><xsl:apply-templates /></sub>
</xsl:template>

<xsl:template match="SUP">
    <sup><xsl:apply-templates /></sup>
</xsl:template>

<xsl:template match="NOBR">
    <nobr><xsl:apply-templates /></nobr>
</xsl:template>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-04-13 13:08:26

如果要创建的元素事先不知道,并且只需要以另一种更具体的方式处理几个已知的元素,那么这里有一个更动态的解决方案

代码语言:javascript
复制
 <xsl:template match="*">
  <xsl:element name="{translate(name(), $vUpper, $vLower)}">
    <xsl:apply-templates select="node()|@*"/>
  </xsl:element>
 </xsl:template>

其中$vUpper$vLower定义为:

代码语言:javascript
复制
<xsl:variable name="vUpper" select=
 "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
 "/>

<xsl:variable name="vLower" select=
 "'abcdefghijklmnopqrstuvwxyz'
 "/>

必须有匹配少数已知元素的模板,这些元素不应该以上述方式处理。,这些更具体的模板将覆盖上面更通用的模板。例如:

代码语言:javascript
复制
 <xsl:template match="specificName">
   <!-- Specific processing here -->
 </xsl:template>

,上面的通用模板,匹配的元素应该覆盖 “身份规则” (模板)。

票数 1
EN

Stack Overflow用户

发布于 2010-04-13 10:14:53

也许是这样:

代码语言:javascript
复制
<xsl:template match="LI|SUB|...">
   <xsl:element name="{translate(name(),
          'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')}">
    <xsl:apply-templates/>
   </xsl:element>
</xsl:template>

我不认为XSLT中有tolower函数(至少1.0中没有)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2628533

复制
相关文章

相似问题

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