The string() function

Smartsite 7.4 - ...

The string() XPath 2.0 function returns the value of arg represented as an string.

XML CopyCode image Copy Code
string fn:string(arg)

Parameters:

  • arg: a node reference. 

Example

XML CopyCode image Copy Code
<html xmlns="http://www.w3.org/1999/xhtml" 
 xmlns:xf="http://www.w3.org/2002/xforms" 
 xmlns:fn="http://www.w3.org/2005/xpath-functions"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <head>
  <title>Example</title>
  <xf:model>
   <xf:instance>
    <data xmlns="">
     <entry>
      <code>abc</code>
      <strings>
       <string index="1">a</string>
       <string index="2">b</string>
       <string index="3">c</string>
       <string index="4">d</string>
       <string index="5" xsi:nil="false">e</string>
       <string index="6" xsi:nil="true"></string>
      </strings>
      <desc>Our <i>favorite</i> shirt!</desc>
     </entry>
    </data>
   </xf:instance>
  </xf:model>
 </head>
 <body>
  <xf:group ref="entry" appearance="full" class="string">
   <xf:label />
   <xf:output value="fn:string(code)" />
   <xf:output value="fn:string(desc)" />
   <xf:output value="fn:normalize-space(fn:string(strings))" />
   <xf:output value="fn:string('literal string')" />
  </xf:group>
 </body>
</html>

The result will be:

abc
Our favorite shirt!
a b c d e
literal string

Namespace

This function is available within the XPath 2.0 namespace (http://www.w3.org/2005/xpath-functions).