How to split a string in Xquery?

Hello, I am using Tamino 4.2.1.1 and I need to know how many words a string contains. So I search for the number of whitespaces using the following code:


declare namespace fn="http://www.w3.org/2004/10/xpath-functions
let $keyword := "lewis and clark"
return fn:tokenize($keyword," ")

But obviously this function is not supported by Tamino. Is there any other way I can get around? Help greatly appreciated.

Hi,

Unfortunately the tokenize() function is not supported by Tamino XQuery. But for counting the white-space separated substrings there exists a workaround. You can use the Tamino function tf:createTextReference() in the following way:

declare namespace tf=“http://namespaces.softwareag.com/tamino/TaminoFunction

count(
let $keyWord := “lewis and clark”
let $keyWordNode := {$keyWord}
return tf:createTextReference($keyWordNode ,“*”)
)

Since tf:createTextReference() expects a node as first argument you have to wrap your keyword into an element node. Applied on this element with the pattern “*” the tf:createTextReference() function creates a text reference for each substring. So you can get the number of substrings by counting the created text references.

Best regards,

Thorsten Fiebig

thanks a lot. It is very helpful.