Home >>XQuery Tutorial >XQuery string join() Function

XQuery string join() Function

XQuery string join() Function

The method XQuery string-join is used for the concatenation of various sequences separated by a specified delimiter.

string-join($sequence as xs:string*, $delimiter as xs:string) as xs:string

Parameter explanation:

$sequence - It specifies the sequence of zero or more strings.

$delimiter - It specifies the delimiter to separate the items of above sequence.

XQuery string-join Example

Let's take an illustration to illustrate use of the feature XQuery string-join. Taking an XQuery expression named "courses.xqy," which has the code below. It will concat all courses offered from the provided expression XQuery.

XQuery Expression: courses.xqy:

let $courses :=  
      string-join($courses/course, ',')  

To read the courses.xqy, build a Java-based XQuery executor system, transfer it to the XQuery Expression Processor, and execute the expression. After that it shows the output.


import java.io.File;  
import java.io.FileInputStream;  
import java.io.FileNotFoundException;  
import java.io.InputStream;  
import javax.xml.xquery.XQConnection;  
import javax.xml.xquery.XQDataSource;  
import javax.xml.xquery.XQException;  
import javax.xml.xquery.XQPreparedExpression;  
import javax.xml.xquery.XQResultSequence;  
import com.saxonica.xqj.SaxonXQDataSource;  
public class XQueryTester {  
   public static void main(String[] args){  
      try {  
      catch (FileNotFoundException e) {  
      catch (XQException e) {  
   private static void execute() throws FileNotFoundException, XQException{  
      InputStream inputStream = new FileInputStream(new File("courses.xqy"));  
      XQDataSource ds = new SaxonXQDataSource();  
      XQConnection conn = ds.getConnection();  
      XQPreparedExpression exp = conn.prepareExpression(inputStream);  
      XQResultSequence result = exp.executeQuery();  
       while (result.next()) {  

Execute XQuery against XML

Put the two files above to the same location. We put them in a folder called XQuery15 on your desktop. Use terminal compile XQueryTester.java. You require JDK 1.5 or later to be enabled on your computer, and optimized classpaths.


javac XQueryTester.java


java XQueryTester