translate - XPath 编辑

XSLT/XPath Reference: XSLT elements, EXSLT functions, XPath functions, XPath axes


The translate function evaluates a string and a set of characters to translate and returns the translated string.

Syntax

translate(string, abc, XYZ)

Arguments

string
The string to evaluate.
abc
The string of characters that will be replaced.
XYZ
The string of characters used for replacement. The first character in XYZ will replace every occurrence of the first character in abc that appears in string.

Returns

The translated string.

Notes

XPath notes that the translate function is not a sufficient solution for case conversion in all languages. A future version of XPath may provide additional functions for case conversion.

However, this is the closest we have at present to a function that can convert a string to uppercase or lowercase.

Example

<xsl:value-of select="translate('The quick brown fox.', 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />

Output

THE QUICK BROWN FOX.
  • If abc is longer than XYZ, then every occurrence of characters in abc that do not have a corresponding character in XYZ will be removed.

Example

<xsl:value-of select="translate('The quick brown fox.', 'brown', 'red')" />

Output

The quick red fdx.
  • If XYZ contains more characters than abc, the extra characters are ignored.

Defined

XPath 1.0 4.2

Gecko support

Supported.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:74 次

字数:2944

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文