交叉编码XSL转换 [英] cross-encoding XSL transformations

查看:189
本文介绍了交叉编码XSL转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些操作来处理XML文件(没什么重要的),XSL在这种情况下很适用。
然而,我的输入文件以UTF-8编码,转换后的文件必须在iso-8859-1中编码。 (我不控制输入文件的编码)

I have some operations to do on an XML files (nothing important) and XSL applies very well in this case. However, my input file is encoded in UTF-8 and the file after the transformation MUST be encoded in iso-8859-1. (I do not control the encoding of the input file either)

一切都很好,除了一些特殊字符存在于utf-8而不是在iso-8859中被转义

Everything goes well except that some special characters present in utf-8 and not in iso-8859 are escaped in the output file.

例如我有
< text>一些带有€字符的文本< / text>
转换为
< text>一些文本带有&#8364;字符< / text>

输出文件中的€是我的问题。

The "€" is in the output file is an issue for me.

由于我们要对那些不在ISO中的特殊字符做一些事情,我首先想到用replace函数手动转换它们:replace(。,'€','euros')
但是在utf-8中只有这么多字符,不是在iso,它很快就无聊...慢了!

As we have to do something with those special characters which are not in ISO, I first thought of transforming them manually with the replace function: replace(., '€', 'euros') But there are just so many characters in utf-8 which are not in iso that it's quickly boring... and slow!

你有更好的解决方案吗? (假设我们可以删除这些字符或将它们转换为任何可行的iso字符)

Do you have a better solution ? (assuming we could just remove those characters or transforming them to any viable iso character)

提前感谢

推荐答案

您有

<xsl:output encoding="iso-8859-1" />

因为这应该是你需要的,真的。如果您的XSL处理器没有正确地将字符转换为目标编码,它自己,它是破碎,你需要使用不同的。

Because that should be all you need, really. If your XSL processor does not correctly translate characters to the target encoding on its own, it is broken and you need to use a different one.

提示


  • 通常 Windows-1252 是人们真正 code> ISO-8859-1 。仔细检查,如果这也适用于你。在两个之间有细微的差别(特别是关于欧元符号,其不存在于 ISO-8859-1 中,但存在于 Windows-1252 ISO-8859-15

  • 在XML文件中缺少XML声明<?xml version =1.0encoding =iso-8859-1?> ,假设使用UTF-8编码。在不是 UTF-8编码的情况下,请务必在文件顶部放置声明。

  • Often Windows-1252 is what people really mean when they say ISO-8859-1. Check closely if that applies to you as well. There are subtle differences between the two (especially with regard to the Euro sign, which does not exist in ISO-8859-1, but does exist in Windows-1252 and ISO-8859-15).
  • Whenever an XML declaration <?xml version="1.0" encoding="iso-8859-1"?> is missing in an XML file, UTF-8 encoding is assumed. Be sure to put a declaration on top of your file whenever is not UTF-8 encoded.

这篇关于交叉编码XSL转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆