lang - XPath 编辑

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


The lang function determines whether the context node matches the given language and returns boolean true or false.

Syntax

lang(string )

Arguments

string
The language code or localization (language and country) code to be matched.

Returns

true if the context node matches the given languages. Otherwise, false.

Notes

  • A node's language is determined by its xml:lang attribute. If the current node does not have an xml:lang attribute, then the value of the xml:lang attribute of the nearest ancestor that has an xml:lang attribute will determine the current node's language. If the language cannot be determined (no ancestor has an xml:lang attribute), this function will return false.
  • If the given string does not specify a country code, this function will match nodes of that language with any country code. The converse is not true.

Given this fragment of XML:

<p xml:lang="en">I went up a floor.</p>
<p xml:lang="en-GB">I took the lift.</p>
<p xml:lang="en-US">I rode the elevator.</p>

And this part of an XSL template:

<xsl:value-of select="count(//p[lang('en')])" />
<xsl:value-of select="count(//p[lang('en-GB')])" />
<xsl:value-of select="count(//p[lang('en-US')])" />
<xsl:value-of select="count(//p[lang('de')])" />

The output might be:

3
1
1
0

Defined

XPath 1.0 4.3

Gecko support

Supported.

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

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

发布评论

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

词条统计

浏览:88 次

字数:2778

最后编辑:7 年前

编辑次数:0 次

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