xquerymarklogictdemarklogic-10

Why fn:substring-after Xquery function could not be used inside ML TDE


In my ML db, we have documents with distributor code like 'DIST:5012' (DIST:XXXX) XXXX is a four-digit number.

currently, in my TDE, the below code works well.

enter image description here

However instead of concat all the raw distributor codes, I want to simply concat the number part only. I used the fn:substring-after XQuery function. However, it won't work. It won't show that distributorCode column in the SQL View anymore. (Below code does not work.)

![enter image description here

What is wrong? How to fix that?

Both fn:substring-after and fn:string-join is in TDE Dialect page. https://docs.marklogic.com/9.0/guide/app-dev/TDE#id_99178


Solution

  • substring-after() expects a single string as input, not a sequence of strings.

    To demonstrate, this will not work:

    let $dist := ("DIST:5012", "DIST:5013")
    return substring-after($dist, "DIST:")
    

    This will:

    for $dist in ("DIST:5012", "DIST:5013")
    return substring-after($dist, "DIST:")
    

    I need to double check what XPath expressions will work in a DTE, you might be able to change it to apply the substring-after() function in the last step:

    fn:string-join( distributors/distributor/urn/substring-after(., 'DIST:'), ';')