【问题标题】:Remove diacritics in whole XML document via XSLT通过 XSLT 删除整个 XML 文档中的变音符号
【发布时间】:2013-10-18 13:36:34
【问题描述】:

我发现很多关于通过 XSLT 函数 translate(source, sourceChars, outputChars) 翻译特定元素/属性的内容,因此对于 translate("čašaž","čšž", "csz") = casaz

我需要 XSLT 模板,它可以翻译每个节点和每个属性。 我不知道源 XML 的结构,所以它必须是通用的,不独立于属性或元素的名称和值。

我正在寻找类似这种伪转换的东西:

  <xsl:template match="@*">
    <xsl:copy>
        <xsl:apply-templates select="translate( . , "čžš","czs")"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="node()">
    <xsl:copy>
      <xsl:apply-templates select="translate( . , "čžš","czs")"/>
    </xsl:copy>
  </xsl:template>

【问题讨论】:

    标签: xml xslt diacritics


    【解决方案1】:

    你可以为那些包含你想要规范化的数据的元素编写模板,下面我为属性值、文本节点、注释节点和处理指令数据编写模板。

    <xsl:param name="in" select="'čžš'"/>
    <xsl:param name="out" select="'czs'"/>
    
    <xsl:template match="*">
      <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
      </xsl:copy>
    </xsl:template>
    
    <xsl:template match="@*">
      <xsl:attribute name="{name()}" namespace="{namespace-uri()}">
        <xsl:value-of select="translate(., $in, $out)"/>
      </xsl:attribute>
    </xsl:template>
    
    <xsl:template match="text()">
      <xsl:value-of select="translate(., $in, $out)"/>
    </xsl:template>
    
    <xsl:template match="comment()">
      <xsl:comment>
        <xsl:value-of select="translate(., $in, $out)"/>
      </xsl:comment>
    </xsl:template>
    
    <xsl:template match="processing-instruction()">
      <xsl:processing-instruction name="{name()}">
        <xsl:value-of select="translate(., $in, $out)"/>
      </xsl:processing-instruction>
    </xsl:template>
    

    【讨论】:

      猜你喜欢
      • 2011-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-08
      • 2012-07-29
      • 1970-01-01
      • 2013-08-04
      相关资源
      最近更新 更多