Flamingo.XPath.value()

The value() method is used to get text value of the specified node found by XPath on the current page.

Syntax

Flamingo.XPath.value(xPath, parent)

Parameters

Parameter Type Description
xPath String XPath expression.
parent Node object Context node against which specified XPath will be executed.

Return Value

Type Description
String Text value of the node or nodes found by XPath.

Note

If specified XPath returns multiple nodes, the function returns concatenated string consisting of all text values of all nodes that were found.

Example 1

The example below demonstrates how to get the value of the TITLE element available on the page.

Source HTML code available on your original desktop site page:

<html>
 <head>
   <title>Document Title</title>
 </head>
</html>

You need to add the following code to your template to display page title on your mobile website:

<!--{= Flamingo.XPath.value('//title') }-->

The result will look like:

Document Title

Example 2

The example below demonstrates how to get values of all list items (LI elements) available on the page.

Source HTML code available on your original desktop site page:

<html>
    <body>
        <ul>
          <li>List Item 1</li>
          <li>List Item 2</li>
        </ul>
    </body>
</html>

You need to add the following code to your template to display values of all list items available on the page:

<!--{= Flamingo.XPath.value('//li') }-->

The result will look like:

List Item 1List Item 2

Example 3

The example below demonstrates how to get node value from the specified context node using XPath.

Source HTML code available on your original desktop site page:

<html>
 <body>
   <ul id="list1">
     <li>List 1 Item 1</li>
     <li>List 1 Item 2</li>
   </ul>
   <ul id="list2">
     <li>List 2 Item 1</li>
     <li>List 2 Item 2</li>
   </ul>
 </body>
</html>

You need to add the following code to your template to get node value from the specified context node using XPath:

<!--{= Flamingo.XPath.value('//li[1]', document.getElementById('list2')) }-->

The result will look like:

List 2 Item 1

See also