2

怎么可能减少这个记录?

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

2 回答 2

2

也许是这样的:

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

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

于 2010-04-13T10:14:53.383 回答
1

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

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

其中$vUpper$vLower定义为:

<xsl:variable name="vUpper" select=
 "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
 "/>

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

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

 <xsl:template match="specificName">
   <!-- Specific processing here -->
 </xsl:template>

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

于 2010-04-13T13:08:26.840 回答