[英]BaseX: Trying to move elements between namespaces in XQuery Update Facility
I would like to normalize XSD input file to put xs:
before any XSD elements without xs:
prepended with XQuery. 我想规范化XSD输入文件,将
xs:
放在没有xs:
任何XSD元素之前xs:
XQuery之前。
copy $c:=doc("test.xsd")
modify
(
if($c/schema)
then
(
for $item in $c//*
where substring($item/text(), 1, 3) != "xs:"
return rename node $item as concat("xs:", $item/text())
)
else ()
)
return $c
Running this xqy on an input XSD without xs:
prepended returns input file unchanged. 在没有
xs:
前置的输入XSD上运行此xqy xs:
返回的输入文件不变。 I do update the $c
and return it. 我确实更新了
$c
并将其返回。 So what is wrong? 那怎么了?
input file: 输入文件:
<?xml version="1.0"?>
<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<element name="note" type="xs:string"/>
</schema>
expected output: 预期输出:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note" type="xs:string"/>
</xs:schema>
PS: It seems that my question causes confusion. PS:看来我的问题引起了混乱。 I need
xs:
present because I have another text processing program which only handles elements with xs:
prefix. 我需要
xs:
present,因为我有另一个文本处理程序,该程序只处理带有xs:
前缀的元素。
This should work (it's pretty similar to your approach): 这应该可以工作(与您的方法非常相似):
copy $doc := doc("test.xsd")
modify (
if($doc/*:schema) then (
for $item in $doc//*
let $name := name($item)
where not(starts-with($name, 'xs:'))
let $new-name := xs:QName('xs:' || replace($name, '^.+:', ''))
return rename node $item as $new-name
)
else ()
)
return $doc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.