Altova MapForce 2024 Basic Edition

Returns true if the context node has an xml:lang attribute with a value that either matches exactly the testlang argument, or is a subset of it. Otherwise, the function returns false.

mf-func-xpath2-lang

 

Languages

XQuery, XSLT 2.0, XSLT 3.0.

 

Parameters

Name

Type

Description

testlang

xs:string

The language code to check, for example, "en".

 

Example

The following XML contains para elements with different values for the xml:lang attribute.

 

<page>
  <para xml:lang="en">Good day!</para>
  <para xml:lang="fr">Bonjour!</para>  
  <para xml:lang="de-AT">Grüss Gott!</para>
  <para xml:lang="de-DE">Guten Tag!</para>
  <para xml:lang="de-CH">Grüezi!</para>
</page>

 

The mapping illustrated below filters only the German paragraphs, regardless of the country variant, with the help of the lang function.

mf-func-xpath2-lang-example

XSLT 2.0 mapping

In the mapping above, for each para in the source, an item is created in the target, conditionally. The condition is provided by a filter which passes on to the target only those nodes where the lang function returns true. That is, only those nodes that have the xml:lang attribute set to "de" (or a subset of "de") will satisfy the filter's condition. Consequently, the mapping output is as follows:

 

<items>
  <item>Grüss Gott!</item>
  <item>Guten Tag!</item>
  <item>Grüezi!</item>
</items>

 

Note that the lang function operates in the context of each para, because of the parent connection between para and item, see also The Mapping Context.

© 2017-2023 Altova GmbH