xslt - 优化<xsl :apply-templates/> for a set of tags

标签 xslt tags identity apply-templates

如何减少这个记录?

<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>

最佳答案

也许是这样的:

<xsl:template match="LI|SUB|...">
   <xsl:element name="{translate(name(),
          'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')}">
    <xsl:apply-templates/>
   </xsl:element>
</xsl:template>

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

关于xslt - 优化<xsl :apply-templates/> for a set of tags,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2628533/

相关文章:

c# - 通过在 xslt 中调用 C# 函数来更改 xml 文件

javascript - 如何在 javascript 函数中嵌入 xslt?

XML 数据类型转换

syntax - 在yaml中写#(在字符串中)

sql-server-2005 - SQL Server 2005中手动实现的Identity列

JavaScript 集合和值对象

java - 通过 XSLT 设置 XML 属性的顺序?

swift - UITextView:添加GestureRecognizer并找到textView的标签

javascript - 如何使用 javascript 在定义的时间延迟后动态更改 <p> 标记数据?

Java Jpa @GeneratedValue 智能生成空值和非空值