[英]BaseX: Trying to move elements between namespaces in XQuery Update Facility
我想规范化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
在没有xs:
前置的输入XSD上运行此xqy xs:
返回的输入文件不变。 我确实更新了$c
并将其返回。 那怎么了?
输入文件:
<?xml version="1.0"?>
<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<element name="note" type="xs:string"/>
</schema>
预期输出:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note" type="xs:string"/>
</xs:schema>
PS:看来我的问题引起了混乱。 我需要xs:
present,因为我有另一个文本处理程序,该程序只处理带有xs:
前缀的元素。
这应该可以工作(与您的方法非常相似):
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.