Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables Can';t确定导入的XQuery模块中未设置变量(E:XPDY0002)的原因_Variables_Xquery_Unset_Exist Db - Fatal编程技术网

Variables Can';t确定导入的XQuery模块中未设置变量(E:XPDY0002)的原因

Variables Can';t确定导入的XQuery模块中未设置变量(E:XPDY0002)的原因,variables,xquery,unset,exist-db,Variables,Xquery,Unset,Exist Db,我正在尝试在XQuery中创建一个从TEXTCLASS到TEI的类型开关。这不是一个非常困难的过程,但它很乏味,所以我尝试尽可能多地自动化它(从长远来看,需要更长的时间和更多的学习) 我用的是氧气12和存在1.4.1 现在我运行transform-tei.xq,它使用gen.xqm中的函数创建了一个方便的dandy transformer。在我添加了函数“convert attr default”(其目的应该是获取节点的属性并将其名称/值转换为小写)之后,transform-tei.xq E[l

我正在尝试在XQuery中创建一个从TEXTCLASS到TEI的类型开关。这不是一个非常困难的过程,但它很乏味,所以我尝试尽可能多地自动化它(从长远来看,需要更长的时间和更多的学习)

我用的是氧气12和存在1.4.1

现在我运行transform-tei.xq,它使用gen.xqm中的函数创建了一个方便的dandy transformer。在我添加了函数“convert attr default”(其目的应该是获取节点的属性并将其名称/值转换为小写)之后,transform-tei.xq

E[localhost]XPDY0002:未设置变量“$attr name”。[第58行第18列][第58行第18列]

我不知道为什么。我猜我错过了一些非常简单的东西,因为XQuery是我尝试自学的第一门语言,虽然O'Reilly的书很棒,但它仍然是一种新的学习方式

xquery version '1.0';

(:  Module: transform-tei.xq
    Date: 24 06 2011
    Desc: Creates a module with functions to perform a basic transform to TEI on a specified xml document.
:)

declare option exist:serialize "method=text media-type=text/text";
import module namespace gen = "http://www.example.com/test/gen" at "xmldb:exist:///db/richmond/test-queries/gen.xqm";

let $doc := doc("/db/richmond/xml-for-typeswitch/wwa0005.0001.005.xml")
let $tags := gen:tags($doc)

let $config :=  
 <config>
   <modulename>text-tei</modulename>
   <namespace>http://www.example.com/test/text-tei</namespace>
 </config>
return 
  gen:create-module($tags, $config)
xquery版本“1.0”;
(:模块:transform-tei.xq
日期:2011年6月24日
Desc:创建一个模块,其中包含一些函数,用于对指定的xml文档执行到TEI的基本转换。
:)
声明选项存在:序列化“方法=文本媒体类型=文本/文本”;
导入模块命名空间gen=”http://www.example.com/test/gen“at”xmldb:exist:///db/richmond/test-queries/gen.xqm";
让$doc:=doc(“/db/richmond/xml表示类型开关/wwa005.0001.005.xml”)
let$tags:=gen:tags($doc)
让$config:=
文本tei
http://www.example.com/test/text-tei
返回
gen:create模块($tags,$config)

xquery版本“1.0”;
(:模块:gen.xqm
注:被盗/修改自http://en.wikibooks.org/wiki/XQuery/Generating_Skeleton_Typeswitch_Transformation_Modules#Generation_Function
日期:2011年6月24日
Desc:提供函数来生成文档中所有标记的列表,并动态创建模块以执行标识转换
:)
模块名称空间gen=”http://www.example.com/test/gen";
声明变量$gen:cr:=“
;”;
将函数gen:tags($docs as node()*)声明为xs:string*{
对于不同值的$tag($docs//*/name(.))
按$tag订购
返回$tag
};
将函数gen:create module($tags as xs:string*,$config as element(config))声明为element(module){
让$modulename:=$config/modulename/text()
让$prefix:=$config/prefix/text()
let$pre:=concat($modulename,“:”,$prefix)
让$namespace:=($config/namespace,“http://mysite/module“”[1]/text()
返回
模块名称空间{$modulename}=“{$namespace}”;
(:从一组标记生成的转换模块
:)
将函数{$pre}convert($nodes as node()*)声明为item()*{{{{$gen:cr}
对于$node中的$node
返回
类型开关($node)
{对于$tags中的$tag
返回
case元素({$tag})返回{$pre}{replace($tag,“:”,“-”)}($node)
}
默认返回
{$pre}转换默认值($node)
}};
将函数{$pre}convert default($node as node())声明为item()*{{{{$gen:cr}
$node
}};
声明函数{$pre}将attr default($attr as attribute()*)转换为item()*{{{{$gen:cr}
对于$attr中的$upper attr
让$attr name:=fn:节点名($upper attr)
let$attr val:=fn:data($upper attr)
返回
属性{$attr name}{$attr val}
}};
{对于$tags中的$tag
返回
将函数{$pre}{replace($tag,“:”,“-”)}($node as element({$tag}))声明为item()*{{{$gen:cr}
元素{小写($tag)}{{
{$pre}convert attr default($node/@*),
{$pre}convert($node/node())
}}{$gen:cr}
}};
}
};

谢谢

乍一看,变量
$attr name
似乎在其引用上方定义了三行。然而,仔细观察就会发现,明显的定义是在构造的
函数
元素的文本元素内容中。在该元素内容中,一个大括号将跳转到表达式模式,其中引用为

因此,定义在生成的查询中,而引用在生成的查询中。有必要将花括号适当对齐,以使两者进入相同的范围。请注意,有两个大括号打开生成的函数,这是单个大括号出现在元素内容中的表示法

xquery version '1.0';

(:  Module: gen.xqm
    Note: Stolen/modified from http://en.wikibooks.org/wiki/XQuery/Generating_Skeleton_Typeswitch_Transformation_Modules#Generation_Function
    Date: 24 06 2011
    Desc: Provides functions to generate a list of all tags in a document and dynamically create a module to perform an identity transformation
:)

module namespace gen = "http://www.example.com/test/gen";

declare variable $gen:cr := "&#13;";

declare function gen:tags($docs as node()*) as xs:string * {
   for $tag in distinct-values ($docs//*/name(.))
   order by $tag
   return $tag
};

declare function gen:create-module($tags as xs:string*, $config as element(config) ) as element(module) {
let $modulename := $config/modulename/text()
let $prefix := $config/prefix/text()
let $pre:= concat($modulename,":",$prefix)
let $namespace := ($config/namespace,"http://mysite/module")[1]/text()
return
<module>
module namespace {$modulename} = "{$namespace}";
(: conversion module generated from a set of tags 

:)
<function>
declare function {$pre}convert($nodes as node()*) as item()* {{ {$gen:cr}
  for $node in $nodes
  return 
     typeswitch ($node)
       {for $tag in $tags
        return 
           <s>case element({$tag}) return {$pre}{replace($tag,":","-")}($node)
           </s>
       }
       default return 
         {$pre}convert-default($node)
  }};
</function>

<function>
declare function {$pre}convert-default($node as node()) as item()* {{ {$gen:cr}
  $node
  }};
</function>

<function>
declare function {$pre}convert-attr-default($attr as attribute()*) as item()* {{ {$gen:cr}
  for $upper-attr in $attr
  let $attr-name := fn:node-name($upper-attr)
  let $attr-val := fn:data($upper-attr)

  return
    attribute { $attr-name } { $attr-val }
  }};
</function>

{for $tag in $tags
 return 
   <function>
declare function {$pre}{replace($tag,":","-")}($node as element({$tag})) as item()* {{ {$gen:cr}
  element {lower-case($tag)} {{
     {$pre}convert-attr-default($node/@*),
     {$pre}convert($node/node()) 
     }}{$gen:cr}
}};
   </function>
}

</module>
};