declare function local:stripNS($name as xs:string?)
as xs:string?
{
if(contains($name, ':'))
then substring($name, functx:index-of-string($name, ':') + 1)
else $name
};
for $x in doc("test.xml")//*[@ref]
let $tmp:=local:stripNS($x/@ref)
return replace value of node $x/@ref with $tmp
ref
とtype
という属性から名前空間を削除したいと考えています。 SO <test ref='haha:123' type='hehe:456'/>
は<test ref='123' type='456'/>
になるはずです。私は以下の私が望む理想的な.xqyファイルで、正しい構文を知らない:BaseX:複数の '置き換え'を行う正しい構文
declare function local:stripNS($name as xs:string?)
as xs:string?
{
if(contains($name, ':'))
then substring($name, functx:index-of-string($name, ':') + 1)
else $name
};
for $x in doc('test.xml')//*[@ref]
let $tmp:=local:stripNS($x/@ref)
return replace value of node $x/@ref with $tmp,
for $x in doc('test.xml')//*[@type]
let $tmp:=local:stripNS($x/@type)
return replace value of node $x/@ref with $tmp
しかし、明らかにそれは構文エラーが含まれています
[XUDY0017] Node can only be replaced once: attribute ref {"123"}.
$ basex -u test.xqy
使用するために上記のコマンドをテスト。出力はtest.xml
に書き戻されます。
入力例を常に入力してください。質問に答える人の生活を楽にし、あなたの実際の問題に適切に答える答えを与えます。 –
@JensEratあなたはすでにそれを持っています。 'test ref = 'haha:123' type = 'hehe:456' />'をコピーして 'test.xml'というローカルファイルに貼り付けてください。 –
確かに。あなたが逃したことがさらに重要なもう一つの事柄:**常に**あなたがエラーメッセージを受け取った場合、エラーメッセージが表示されます。エラーメッセージを投稿した場合は、恐らくコードをコピーしなくてもすぐにこの問題を発見したでしょう。 –