The substring-before() function

Smartsite 7.4 - ...

The substring-before() XPath 2.0 function returns the part of arg1 that precedes the first occurrence of arg2.

XML CopyCode image Copy Code
string fn:substring-before(arg1, string arg2)

Parameters:

  • arg1: a node reference or string literal.
  • string arg2.

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">
 <head>
  <title>Example</title>
  <xf:model>
   <xf:instance>
    <data xmlns="">
     <alphabet>abcdefghi</alphabet>
    </data>
   </xf:instance>
  </xf:model>
 </head>
 <body>
  <xf:group>
   <xf:output value="fn:substring-before(alphabet, 'def')" />
   <xf:output value="fn:substring-before('abcdef', 'def')" />
  </xf:group>
 </body>
</html>

The result will be:

abc
abc

Namespace

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