Updated March 29, 2023
Definition of Xpath Substring
Substring comprised of three parts one is a target, length, and start index. This method executes the sub-string from the target string and works along with the specified length from the start-index values. If the user doesn’t provide the length argument, it executes the string from the specified start index to the end character of the target string. The substring can be used before and after according to the function requirement which follows the standards of XSLT. In this article, the definition, examples, and working of substring is explained in brief.
What is Xpath substring?
In Xpath, the substring is case-sensitive which returns the function of the given input string that is executed before the first occurrence which is executed before the upcoming argument. The function has been executed in the Xpath string function list. If the passed argument is not the string type and it is converted to a string first then it is changed to a string() function where the result is evaluated later. The function substring-before is case-sensitive in XSLT. The substring-after functions execute the section of string declared in the argument of string which is specified after the execution of the substring. If the next string is null, it executes the empty string which is declared as output. The function of the string is to evaluate the string manipulation in text form. The string function supports and executes an atomic value that is not a simple node. The substring function has two string values that execute the specific string which is present in the user-given data. The other part of the string can be executed and returned as a node.
Using Xpath Substring
The Xpath substring can be used with the below options,
Starts-with is composed of two strings string 1 and string 2 which returns once the first string is started and then followed by the second string. The contain option is used to return when the strings are true and holds the value of string 2.
The substring option is used which contains a string, offset, and length value that returns only the part of the string. The concerned section begins with the offset value with the provided length.
The option Substring-before is used in the section of string 1 where it occurs before the beginning of string 2.
The option substring-after is used to return the section of string where it occurs after the beginning of string 2.
The string-length option is used to return the entire character and its count in length terms
The normalize-space option is used to trim the lead and trail space in the string
The translate option is used when three strings are used. This option returns the 1st string value once the matching character in the second string is found. Then both strings can be replaced by the values in string 3.
The concat option is used to concatenate all the available strings.
The format-number is used to execute the format version of number 1 that is implied after the format string 1 and then execute the string 2 as the local string used as optional.
The substring option is used to find the suitable option or search for the beginning character in the substring or it can be used at the end also in the Xpath node. It is used to fetch the section of a substring from the Xpath node by defining the end and beginning index.
Examples of a substring
The substring is used in three scenarios, one substring-before, substring after, and substring. The implementation of sub-string after is given below,
string substring – after
(
string
string
)
This function gets two inputs where the first one is helped in the search and the next string helps with the search option for the first string.
The substring – after option gets the value of two strings and executes the string value present next to the mentioned string and then the concerned part of the string is fetched and returned.
Substring – after (’14-April-2000, ‘-‘) = April – 2000
Substring – after (’14-April-2000, ‘-‘) = April – 2000
substring – after (’14 April 2000, ‘ ’) = April 2000
Substring – after (’14-April-2000, ‘-‘) = ”
substring – after (‘nn-mm’,’-‘) = nn
substring – after (‘nn-mm’,’m’) = mm-n
substring – after (‘ nn-mm”,’n’) = n
substring – after (‘ nn-mm,’d’) = return null value
The XSLT has multiple in-built functions and a defined namespace which is given before any function as a default prefix. Additional feature present in XSLT is used to process the elements. The substring–before the option is used to get the input as two strings and is executed when the first string is searched and the next string is used to find the first string. The XSLT fails to use the replace option and determine the end and start function. Although there are varied functions for manipulation of strings, it lends the user to recurse the string process. The string functions work on XSLT manipulation with attributes and data. It also uses variables to work on fundamental XSLT. The functions with the date option include the resultant value.
Substring – before (’22-Jan-1992′, ‘-‘) = ‘22’
Substring – before (’22-Jan-1992’, ‘-‘) = ‘22’
Substring – before (’22-Jan-1992’, ‘ ’) = ‘22’
Substring – before (’22-Jan-1992′, ‘-‘) = ”
Substring – before (cc-aa,’-‘) = cc
Substring – before (cc-aa,’-‘),’c’) = (empty string)
Substring – before (cc-aa,’a’) = aa-
Substring – before (cc-aa,’d’) = (empty string)
Substring – before (cc, aa)
Substring – before (‘carrot – rabbit’, ‘-‘) // it executes the value placed before hyphen. This function executes the empty string if the case is absent in the second string that is comprised in the second string. In Xpath, the null sequence is displayed as a result if the operand values of the first two strings are empty.
Conclusion
Hence in this article, the substring in Xpath is discussed, and the values, substring-before, and substring after are used to fetch the result of strings.
Recommended Articles
This is a guide to Xpath Substring. Here we discuss the Definition, Overviews, What is the Xpath substring? and examples with code implementation respectively. You may also have a look at the following articles to learn more –