Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

FOR LOOP in xpath reg-ex

Options
Parasofttoudaya
Parasofttoudaya Posts: 232 ✭✭

for $item in (/root/Json[1]/item[*])
return
$item/account[1]/text()

the above statement return no.of items, whereas applying replacement is not working

for $item in (/root/Json[1]/item[*])
return
replace($item/account[1]/text(),'abc','xyz')

It returns only the top row.

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,231 ✭✭✭
    Options

    From an earlier reply:

    the built-in Data Bank and Transformer tools currently support XPaths that return nodes from the original document and not strings or a combination of nodes and strings

    The work around mentioned in various other threads on the forums involve using "parse-xml" function. For example:

    for $item in (/root/Json[1]/item[*])
    return parse-xml(concat("<root>", replace($item/account[1]/text(), "abc", "xyz"), "</root>"))/root/text()
    
  • benken_parasoft
    benken_parasoft Posts: 1,231 ✭✭✭
    Options

    As an aside, the "only fetches the first value" issue has to do with SOAtest using JAXP to evaluate the XPath. Some general information about this can also be found on stackoverflow. Internally, SOAtest would have to use a different XPath API under the hood.

  • benken_parasoft
    benken_parasoft Posts: 1,231 ✭✭✭
    Options

    the built-in Data Bank and Transformer tools currently support XPaths that return nodes from the original document and not strings or a combination of nodes and strings

    For the next release, XPaths that return lists of strings will work as expected. Using "parse-xml" to convert the list of strings to a list of text nodes will no longer be needed.