0

我正在使用 Editix 运行一些 XML 查询,并且试图从标签中获取“角色”属性......

<actor id="5" role="Richie Cusack"/>

....并在我生成的标签之间插入值,就像这样....

<role>Richie Cusack</role>

...但是我正在运行的查询是将角色属性值插入回我围绕它的标签的属性中,例如...

<role role="Richie Cusack"/>

这是我的 XQuery 查询....

<results>
{
let $ms := doc("xmlPath.xml"),
for $m in $ms//movie
    for $r in $m/actor/@role
    return <result>
        {$m/title}<role>{$r}</role>
         </result>
}
</results>

...这是 XML 文件的结构...

<movies>
  <movie>
    <title>A History of Violence</title>
    <year>2005</year>
    <country>USA</country>
    <genre>Crime</genre>
    <summary>Tom Stall, a humble family man and owner of a 
    .</summary>
    <director id="1"/>
    <actor id="5" role="Richie Cusack"/>
 </movie>
  <movie>
    <title>Heat</title>
    <year>1995</year>
    <country>USA</country>
    <genre>Crime</genre>
    <summary>Hunters and their prey--Neil and his professional 
    .... </summary>
    <director id="6"/>
    <actor id="7" role="Lt. Vincent Hanna"/>
</movies>

如何仅提取属性的值并将其嵌入标签之间,而不以属性的形式插入自身?

4

1 回答 1

0

在这个查询中,$r它本身是一个属性,所以它被添加到父节点<role>(你可以注意到同样的事情正在发生$m/title- 元素本身,而不仅仅是它的文本,被添加到<result>)。

要获得您正在寻找的行为,请执行以下操作:

<role>{string($r)}</role>
于 2013-02-11T08:57:49.920 回答