You may also what to hoist the fn:doc call out of the "for"
clause to prevent it being evaluated on every iteration, which
isn't necessary.

   It's also better for readability and comprehension to use
a more descriptive name for the "for" variable.  The variable
$values in your example only ever contains one of the items
in the sequence returned by fn:tokenize().  Its name implies
that it holds them all.  A less generic name can also better
express the intent.

let $input := "abc/def/ghi"
let $doc := fn:doc("externalFile.xml")
return string-join(
  for $code in fn:tokenize($input,"\/")
  return $doc//entry[@code = $code]/@value/string()
,"/")

On Jan 21, 2013, at 10:34 AM, John Snelson wrote:

> You want to run string-join() on the result of the entire FLWOR 
> expression, not in the return clause where it is run once per iteration 
> of the FLWOR:
> 
> let $input := "abc/def/ghi"
> return string-join(
>   for $values in fn:tokenize($input,"\/")
>   return fn:doc("externalFile.xml")//entry[@code = $values]/
>     @value/string()
> ,"/")
> 
> John
> 
> On 21/01/13 10:31, sini narayanan wrote:
>> 
>> Hi All,
>> 
>> I have a string which has multiple values in it.
>> 
>> Example:
>> let $input := "abc/def/ghi"
>> 
>> External xml file have the following values:
>> <root>
>>     <entry code="abc" value="123"/>
>>     <entry code="def" value="456"/>
>>     <entry code="ghi" value="789"/>
>> </root>
>> 
>> 
>> My requirement is to split the input string( "abc/def/ghi") based on the
>> "/" character, get the corresponding value from the external xml and
>> then merge them back using "/".
>> So the output is expected to be 123/456/789
>> 
>> 
>> My code :
>> 
>> let $input := "abc/def/ghi"
>> return
>> for $values in fn:tokenize(($input ),"\/")
>> let $value := fn:doc("externalFile.xml")//entry[@code =
>> $values]/@value/string()
>> return
>> fn:string-join(($value),"/")
>> 
>> 
>> This does not give me the expected result. How do I achieve this. Please
>> help.
>> 
>> 
>> Thanks,
>> Sini
>> 
>> 
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>> 
> 
> 
> -- 
> John Snelson, Lead Engineer                    http://twitter.com/jpcs
> MarkLogic Corporation                         http://www.marklogic.com
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general

---
Ron Hitchens {mailto:[email protected]}   Ronsoft Technologies
     +44 7879 358 212 (voice)          http://www.ronsoft.com
     +1 707 924 3878 (fax)              Bit Twiddling At Its Finest
"No amount of belief establishes any fact." -Unknown




_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to