namespaces - XQuery:本地函数中的命名空间问题

标签 namespaces xquery

我的本地函数存在以下问题。

以下功能:

declare function local:exp($w as node()) as element()* {
 for $e in ($w/e)
 let $exp:= QName ("myns", "real")
 return 
  element {$exp}{ 
   attribute resource {$e/@lang}
  }
};

生成这个xml:
<real xmlns="myns" resource="eng"/>

真正需要的是:
<myns:real rdf:resource="lang"/>

我怎样才能做到这一点?
  • 我该如何解决这个问题?
  • 如何为资源属性添加“rdf”作为 NS。

  • 提前致谢。

    最佳答案

    您可以将前缀分配给 QName,如下所示:

    let $exp:= QName ("urn:my-namespace", "myns:real")
    

    可能解决此问题的最佳方法是在查询中声明这些命名空间,并仅通过前缀引用它们:
    declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
    declare namespace myns="urn:my-namespace";
    
    declare function local:exp($w as node()) as element()* {
     for $e in $w/e
     return 
      element myns:real { 
       attribute rdf:resource {$e/@lang}
      }
    };
    

    请注意,您可以使用直接构造函数来简化您的函数:
    declare function local:exp($w as node()) as element()* {
     for $e in $w/e
     return <myns:real rdf:resource="{$e/@lang}" />
    };
    

    关于namespaces - XQuery:本地函数中的命名空间问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4245995/

    相关文章:

    c# - C# 中的命名空间与 Java 和 Python 中的导入

    Angular-不能使用命名空间 'moment' 作为类型

    sql - 在 SQL Server 的 XML 文档中查找节点顺序

    xquery - 马克逻辑cts :document-query

    search - 转换 cts :search to search:search 的逻辑

    php - 使用基于 Composer 的库而不使用 Composer 包裹在同名类中?

    asp.net-mvc - 你如何在 Asp.Net MVC 3 中的所有 View 中实现 @using?

    php - 在 php 中自动加载整个命名空间(用于函数而不是类)

    xquery - 如何防止xdmp :node-replace from adding a namespace declaration?

    javascript - 如何在 XQuery 函数中转义 Javascript