Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

XQuery: Item expected, sequence found error

XML:

<data>
    <providers>
        <provider num="v1">
            <name>Smith</name>
            <state>20</state>
            <city>London</city>
        </provider>
        <provider num="v2">
            <name>Jones</name>
            <state>10</state>
            <city>Paris</city>
        </provider>
        <provider num="v3">
            <name>Adams</name>
            <state>30</state>
            <city>Athens</city>
        </provider>
    </providers>
 </data>

XQuery:

let $p := doc("providers.xml")/data/providers/provider
where $p/state > 15
return <cities>{concat($p/city/text(), ' , ')}</cities>

I want the output to be the name of the cities, one after the other separated by comma, but I get the error: item expected, sequence found.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It is complaining about the concat() function where the first parameter is a sequence of strings. It expects each item you want to concatenate to be specified as separate parameters to that function (it doesn’t spread the sequence to params).

You should use string-join() instead, to produce a comma separated string with each of the cities:

<cities>{string-join($p/city/text(), ' , ')}</cities>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading