编写一个xquery,将cdcatalog.xml转换为';国家';元素作为';cd&x27;要素
我试图编写一个xquery语句,转换以下cdcatalog.xml,以便将“country”元素更改为“cd”元素上的一个属性,并向“cd”元素添加一个“id”属性,该属性是递增整数(1,2,3…)。Flower是否在此应用,或者我必须使用其他功能来添加和执行更改? cdcatalog.xml如下所示:编写一个xquery,将cdcatalog.xml转换为';国家';元素作为';cd&x27;要素,xquery,Xquery,我试图编写一个xquery语句,转换以下cdcatalog.xml,以便将“country”元素更改为“cd”元素上的一个属性,并向“cd”元素添加一个“id”属性,该属性是递增整数(1,2,3…)。Flower是否在此应用,或者我必须使用其他功能来添加和执行更改? cdcatalog.xml如下所示: <catalog> <cd> <title>Empire Burlesque</title> <artist>Bo
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>Still got the blues</title>
<artist>Gary Moore</artist>
<country>UK</country>
<company>Virgin records</company>
<price>10.20</price>
<year>1990</year>
</cd>
</catalog>
皇帝讽刺剧
鲍勃·迪伦
美国
哥伦比亚
10.90
1985
隐藏你的心
邦尼泰勒
英国
哥伦比亚唱片公司
9.90
1988
最成功的
多莉·帕顿
美国
RCA
9.90
1982
还是那么忧郁吗
加里摩尔
英国
维珍唱片
10.20
1990
输出应该是这样的
<catalog>
<cd id="1" country="USA">
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd id="2" country="UK">
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
皇帝讽刺剧
鲍勃·迪伦
哥伦比亚
10.90
1985
隐藏你的心
邦尼泰勒
哥伦比亚唱片公司
9.90
1988
谢谢!非常有用的回答。
element catalog {
for $cd at $pos in doc('cdcatalog.xml')/catalog/cd
return
element cd {
attribute id { $pos },
attribute country { $cd/country },
$cd/* except $cd/country
}
}