1

File common.xml:

<common>
  <os1>Windows 7</os1>
</common>

File item.xml:

<item>
  <os>common/os1</os>
</item>

So the os node in the item.xml file contains an XPath expression pointing to a node in the common.xml file. How can I get the actual value of the node pointed by the XPath expression (Windows 7). If I use $input-context/item/os I get common/os1.

I'm using zorba-xquery and I have declared:

declare variable $input-context external;
declare variable $common-context external;
4

1 回答 1

2

这可以通过反射模块的 eval 函数来完成:

import module namespace reflection = "http://www.zorba-xquery.com/modules/reflection";

declare variable $common-context :=
  document {
    <common>
      <os1>Windows 7</os1>
    </common>
  };

declare variable $input-context :=
  document {
    <item>
      <os>common/os1</os>
    </item>
  };

let $path := $input-context/item/os/text()
let $query := fn:concat('$common-context/', $path, '/text()')
return
  reflection:eval($query)
于 2012-02-16T08:57:06.033 回答